十六进制数怎么转化为十进制数?

jukyy 2003-03-27 04:17:55
小问题一个,谢谢!
...全文
205 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
POLOM 2003-04-11
  • 打赏
  • 举报
回复
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
char *string = "ABC123", *endptr;
long lnumber;

/* strtol converts string to long integer */
lnumber = strtol(string, &endptr, 16);
printf("string = %s long = %ld\n", string, lnumber);

return 0;
}
POLOM 2003-04-11
  • 打赏
  • 举报
回复
用这个函数:(stdlib.h中)
long strtol(const char *s, char **endptr, int radix);

对参数radix的解释:
If radix is between 2 and 36, the long integer is expressed in base radix. If radix is 0, the first few characters of s determine the base of the value being converted.

First character Second character String interpreted as...

0 1 - 7 Octal
0 x or X Hexadecimal
1 - 9 Decimal

If radix is 1, it is considered to be an invalid value. If radix is less than 0 or greater than 36, it is considered to be an invalid value.

Any invalid value for radix causes the result to be 0 and sets the next character pointer *endptr to the starting string pointer.
fleamboy 2003-04-11
  • 打赏
  • 举报
回复
这样最简单:

String sHex="FE";
sHex = "0x" + sHex;
int nDec=StrToInt(sHex);
lyzq 2003-04-11
  • 打赏
  • 举报
回复
struct DateTimeB
{
byte YearLow;
byte YearHigh;
byte Month;
byte Day;
byte Hour;
byte Minute;
byte Second;
};
struct DateTimeI
{
int Year;
int Month;
int Day;
int Hour;
int Minute;
int Second;
};
TimeBg.Year=256*BeginTime.YearHigh+BeginTime.YearLow;
TimeBg.Month=BeginTime.Month;
TimeBg.Day=BeginTime.Day;
TimeBg.Hour=BeginTime.Hour;
TimeBg.Minute=BeginTime.Minute;
TimeBg.Second=BeginTime.Second;
这是我刚写的,没来得及改就抄到这里了其中TimeBg里的所有成员都是INT型
BeginTime中的所有成员都是byte型,直接赋值就可以拉,你看适合不适合你的需要?
jukyy 2003-04-03
  • 打赏
  • 举报
回复
有了,我自己写了一个函数。
猎人66 2003-03-27
  • 打赏
  • 举报
回复
AnsiString Str="0x65";
int i=StrToInt(Str);
jukyy 2003-03-27
  • 打赏
  • 举报
回复
的确没有HexToInt的。
chifengwatch(chifengwatch) 什么意思呀,看不明白。
chifengwatch 2003-03-27
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i = 0x65 ;
Button1->Caption = IntToStr( i ) ;
}
//---------------------------------------------------------------------------
tokens 2003-03-27
  • 打赏
  • 举报
回复
错了。。好象只有IntToHex,没有HexToInt.sorry
jimzj 2003-03-27
  • 打赏
  • 举报
回复
StrToInt
tokens 2003-03-27
  • 打赏
  • 举报
回复
HexToInt

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧