C/C++: 十六进制转10进制源码 收藏
C/C++: 十六进制转10进制源码
收藏
view plain
copy to clipboard
print
?
int
hex_char_value(
char
c)
{
if
(c >=
'0'
&& c <=
'9'
)
return
c -
'0'
;
else
if
(c >=
'a'
&& c <=
'f'
)
return
(c -
'a'
+ 10);
else
if
(c >=
'A'
&& c <=
'F'
)
return
(c -
'A'
+ 10);
assert(0);
return
0;
}
int
hex_to_decimal(
const
char
* szHex,
int
len)
{
int
result = 0;
for
(
int
i = 0; i < len; i++)
{
result += (int
)pow((
float
)16, (
int
)len-i-1) * hex_char_value(szHex[i]);
}
return
result;
}
int hex_char_value(char c)
{
if(c >= '0' && c <= '9')
return c - '0';
else if(c >= 'a' && c <= 'f')
return (c - 'a' + 10);
else if(c >= 'A' && c <= 'F')
return (c - 'A' + 10);
assert(0);
return 0;
}
int hex_to_decimal(const char* szHex, int len)
{
int result = 0;
fo
相关文档:
#include <stdio.h>
#define bits(p, d) { \
int _tmp=p->d, _bits=0; \
for (p->d=1; p->d; p->d<<=1) \
_bits++; \
p->d=_tmp; \
printf("%s->%s has %d bits", #p, #d, _bits); \
}
typedef struct _s{
int a:4;
} S;
int main()
{
S tmp, ......
转自:http://hi.baidu.com/ssrt_hanbing/blog/item/62e3b934598eeb82a71e1238.html
通过高低位转换。
package com.commnt;
import java.net.*;
import java.io.*;
public class Client {
public String send(String address, int port, String str) {
OutputStream os = null;
DataInpu ......
理解c中的序列点
http://blog.chinaunix.net/u1/42826/showart_364176.html
让我们来看看下面的代码:
int i=7;
printf(”%d\n”, i++ * i++);
你认为会返回什么?56?no。正确答案是返回 49?很多人会问为什么?难道不该打印出56吗?在ccfaq中有非常详尽的解释,根本原因在于c中的序列 ......
BSS
未初始化的数据
DATA
初始化的数据
TEXT(code)
代码
在C中有全局、局部(自动变量)和静态变量。
全局变量在C语言里表示时,在函数之外的就是全局变量,即在函数外所申明的变量;而静态变量可以放在函数外,也可以放在函数内。全局变量有两个作用:第一,当在函数外申 ......