帮助签名和无符号64位 [英] help signed and unsigned in 64bits
问题描述
以下情况会发生什么...
长a = -2;
longlong b = a
长c;
c = *(ulonglong *)& b;
b = c;
当
长d;
d = *& b;
b = d;
什么将是b的价值?什么时候会失去上面的32位呢?
问候
amit
Hi,
What will happen in following scenario..
long a = -2;
longlong b = a
long c;
c = *(ulonglong *)&b;
b = c;
also when
long d;
d = *&b;
b = d;
What will be the value of b ? When will it lose the upper 32bits ?
regards
amit
推荐答案
2004年4月6日17:44:38 -0700, an******@yahoo.com (amit )写道:
On 6 Apr 2004 17:44:38 -0700, an******@yahoo.com (amit) wrote:
以下情况会发生什么...
长a = -2;
longlong b = a
长c;
c = *(ulonglong *)& b;
b = c;
当
长d;
d = *& b;
b = d;
b的值是多少?什么时候会失去上面的32位?
问候
amit
Hi,
What will happen in following scenario..
long a = -2;
longlong b = a
long c;
c = *(ulonglong *)&b;
b = c;
also when
long d;
d = *&b;
b = d;
What will be the value of b ? When will it lose the upper 32bits ?
regards
amit
如果我误解了你写的任何内容,请告诉我。在那里:
#include< stdio.h>
int main()
{
长a = -2;
printf(" a =%ld \ n",a);
printf( a(unsigned)=%uld \ n \ n,a);
long long b = a;
printf(" b =%lld \ n",b);
printf(" b(unsigned)=%llu \ n \ nn",b);
long c;
c = *(unsigned long long *)& b;
printf(" c(via pointers)=%ld \ n" ;,c);
printf(c(通过指针,无符号)=%uld \ n \ n,c);
/ *我添加了这个(为什么要用指针来打扰?* /
c =(unsigned long long)b;
printf(" c(无指针) =%ld \ n",c);
printf(" c(no pointers,unsig) ned)=%uld \ n \\ nnn,c);
b = c;
长d;
d = *& b;
printf(" d =%ld \ n",d);
printf(" d(unsigned)=%uld \\ \\ n \\ n \\ n \\ n \\ n',d);
b = d;
printf(" b(来自d)=%lld \ n", b);
printf(" b(来自d)(unsigned)=%llu \ n \ nn",b);
b = (未签名)d;
printf(" b(来自无符号d)=%lld \ n",b);
printf(" b(来自无符号) d)(未签名)=%llu \ n \\ nn,b);
返回0;
}
输出:
a = -2
a(未签名)= 4294967294ld
b = -2
b (未签名)= 18446744073709551614
c(通过指针)= -2
c(通过指针,无符号)= 4294967294ld
c(无指针)= -2
c(无指针,无符号)= 4294967294ld
d = -2
d(无符号) = 4294967294ld
b(来自d)= -2
b(来自d)(未签名)= 18446744073709551614
b(来自无符号d)(无符号)= 4294967294
所以请注意,你输了最后输了32位从
d分配给c,/ if / you首先将d值转换为无符号。只要您将
作为签名值进行分配,您将获得签名扩展。
(使用Comeau 4.3.3编译) ,Dinkum Unabridged图书馆)
-leor
-
Leor Zolman --- BD软件--- www.bdsoft.com
C / C ++,Java现场培训,Perl和Unix
C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html
2004年4月6日17: 44:38 -0700, an******@yahoo.com (amit)写道:
On 6 Apr 2004 17:44:38 -0700, an******@yahoo.com (amit) wrote:
以下情况会发生什么...
长a = -2;
longlong b = a
long c;
c = *(ulonglong *)& b;
b = c;
当
长d;
d = *& b;
b = d;
b的价值是多少?什么时候会失去上面的32位?
问候
amit
Hi,
What will happen in following scenario..
long a = -2;
longlong b = a
long c;
c = *(ulonglong *)&b;
b = c;
also when
long d;
d = *&b;
b = d;
What will be the value of b ? When will it lose the upper 32bits ?
regards
amit
如果我误解了你写的任何内容,请告诉我。在那里:
#include< stdio.h>
int main()
{
长a = -2;
printf(" a =%ld \ n",a);
printf( a(unsigned)=%uld \ n \ n,a);
long long b = a;
printf(" b =%lld \ n",b);
printf(" b(unsigned)=%llu \ n \ nn",b);
long c;
c = *(unsigned long long *)& b;
printf(" c(via pointers)=%ld \ n" ;,c);
printf(c(通过指针,无符号)=%uld \ n \ n,c);
/ *我添加了这个(为什么要用指针来打扰?* /
c =(unsigned long long)b;
printf(" c(无指针) =%ld \ n",c);
printf(" c(no pointers,unsig) ned)=%uld \ n \\ nnn,c);
b = c;
长d;
d = *& b;
printf(" d =%ld \ n",d);
printf(" d(unsigned)=%uld \\ \\ n \\ n \\ n \\ n \\ n',d);
b = d;
printf(" b(来自d)=%lld \ n", b);
printf(" b(来自d)(unsigned)=%llu \ n \ nn",b);
b = (未签名)d;
printf(" b(来自无符号d)=%lld \ n",b);
printf(" b(来自无符号) d)(未签名)=%llu \ n \\ nn,b);
返回0;
}
输出:
a = -2
a(未签名)= 4294967294ld
b = -2
b (未签名)= 18446744073709551614
c(通过指针)= -2
c(通过指针,无符号)= 4294967294ld
c(无指针)= -2
c(无指针,无符号)= 4294967294ld
d = -2
d(无符号) = 4294967294ld
b(来自d)= -2
b(来自d)(未签名)= 18446744073709551614
b(来自无符号d)(无符号)= 4294967294
所以请注意,你输了最后输了32位从
d分配给c,/ if / you首先将d值转换为无符号。只要您将
作为签名值进行分配,您将获得签名扩展。
(使用Comeau 4.3.3编译) ,Dinkum Unabridged图书馆)
-leor
-
Leor Zolman --- BD软件--- www.bdsoft.com
C / C ++,Java现场培训,Perl和Unix
C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html
2004年4月7日星期三01:13:59 GMT,Leor Zolman< le ** @ bdsoft.com>写道:
嗯,这是我第一次尝试显示多长的价值,而在我的困惑中,我最终得到了一个假的 d"四种格式
转换(当%ul足以支持普通的无符号长时,我将%uld放入)。
幸运的是,这并没有真正打破输出,除了有b / b
尾随,在4行末尾没有意义的''d'。对不起。
-leor
P.S.我花了一段时间才找到一个显示长期价值的平台
!好东西我有Dinkum lib躺在... ;-)
-
Leor Zolman --- BD软件--- www.bdsoft.com
C / C ++,Java现场培训,Perl和Unix
C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html
On Wed, 07 Apr 2004 01:13:59 GMT, Leor Zolman <le**@bdsoft.com> wrote:
Well, that was my very first time attempting to display values of long
longs, and in my confusion I ended up with a spurious "d" in four format
conversions (I put %uld when %ul was sufficient for a plain unsigned long).
Fortunately, that didn''t really break the output, except that there''s a
trailing, meaningless ''d'' at the end of 4 of the lines. Sorry about that.
-leor
P.S. It took me a while to find a platform that displayed long long values
at all! Good thing I had that Dinkum lib lying around... ;-)
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
这篇关于帮助签名和无符号64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!