IntToStr(num),num的范围有多大?

blankman 2002-05-13 12:35:50
我最近在做程序时遇到了这样的问题,在结构中我如下定义,
struct _tcp
{
....
unsigned long Seq;
....
} *tcp;

Edit1->Text = IntToStr(ntohl(tcp->Seq));
Edit1 中的内容有时是负的,我不知道是为什么。我用了如下的检测方法:
if ( ntohl(tcp->Seq)<0 ) ShowMessage("num<0");
但是在程序运行时没有执行这条语句,说明传进去的数值是正的,请高手指点弥经。
...全文
128 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
redsuns2001 2002-05-13
  • 打赏
  • 举报
回复
INT类型有多大,它就有多大呀。
在BCB中,Int是32位的。所以你可自己计算一下。
phenix_jjg 2002-05-13
  • 打赏
  • 举报
回复
IntToStr(2147483647)

IntToStr converts an integer into a string containing the decimal representation of that number.


最大的整数是2147483647
phenix_jjg 2002-05-13
  • 打赏
  • 举报
回复
Type Range Format
Integer ?147483648..2147483647 signed 32-bit
Cardinal 0..4294967295 unsigned 32-bit
Fundamental integer types include Shortint, Smallint, Longint, Int64, Byte, Word, and Longword.
phenix_jjg 2002-05-13
  • 打赏
  • 举报
回复
An integer type represents a subset of the whole numbers. The generic integer types are Integer and Cardinal; use these whenever possible, since they result in the best performance for the underlying CPU and operating system. The table below gives their ranges and storage formats for the current 32-bit Object Pascal compiler.

Type Range Format
Integer ?147483648..2147483647 signed 32-bit
Cardinal 0..4294967295 unsigned 32-bit
Fundamental integer types include Shortint, Smallint, Longint, Int64, Byte, Word, and Longword.

Type Range Format
Shortint ?28..127 signed 8-bit
Smallint ?2768..32767 signed 16-bit
Longint ?147483648..2147483647 signed 32-bit
Int64 ?^63..2^63? signed 64-bit
Byte 0..255 unsigned 8-bit
Word 0..65535 unsigned 16-bit
Longword 0..4294967295 unsigned 32-bit
jishiping 2002-05-13
  • 打赏
  • 举报
回复
Edit1->Text = IntToStr(ntohl(tcp->Seq));
这儿 tcp->Seq 是无符号的长整数,当它大于等于0x80000000时,用
IntToStr来输出时,被转换成有符号的整数就变成负的啦。
char buf[17];
sprintf(buf, "%lu", tcp->Seq);
Edit1->Text = buf;
xiaoguoru 2002-05-13
  • 打赏
  • 举报
回复
最大64位

13,826

社区成员

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

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