最奇怪的问题...... [英] The strangest problem....

查看:52
本文介绍了最奇怪的问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有:

unsigned int myvalue = 0;

unsigned char mytest = 0;


mytest = 0x34 ;

myvalue = mytest<<< 24;


然后myvalue得到值0x1A000000 !!!!!

怎么样这可能吗?不应该是0x34000000 ???


最好的问候

Jannick

Hi I have:
unsigned int myvalue=0;
unsigned char mytest=0;

mytest=0x34;
myvalue = mytest<<24;

Then myvalue gets the value 0x1A000000!!!!!
How is this possible? Should''nt it be 0x34000000???

Best Regards
Jannick

推荐答案



" Jannick" < Ja*@janse.dk>在消息中写道

news:bm ********** @ news.net.uni-c.dk ...

"Jannick" <Ja*@janse.dk> wrote in message
news:bm**********@news.net.uni-c.dk...
嗨我有:
unsigned int myvalue = 0;
unsigned char mytest = 0;

mytest = 0x34;
myvalue = mytest<< 24;
然后myvalue得到值0x1A000000 !!!!!
这怎么可能?不应该是0x34000000 ???

最好的问候
Jannick
Hi I have:
unsigned int myvalue=0;
unsigned char mytest=0;

mytest=0x34;
myvalue = mytest<<24;

Then myvalue gets the value 0x1A000000!!!!!
How is this possible? Should''nt it be 0x34000000???

Best Regards
Jannick




你确定,它的不是你节目中的拼写错误? 0x1A000000是0x34<< 23

Allan



Are you sure, its not a typo in your program? 0x1A000000 is 0x34<<23
Allan




" Jannick" < Ja*@janse.dk> schrieb im Newsbeitrag

news:bm ********** @ news.net.uni-c.dk ...

"Jannick" <Ja*@janse.dk> schrieb im Newsbeitrag
news:bm**********@news.net.uni-c.dk...
嗨我有:
unsigned int myvalue = 0;
unsigned char mytest = 0;

mytest = 0x34;
myvalue = mytest<< 24;
然后myvalue得到值0x1A000000 !!!!!
这怎么可能?不应该是0x34000000 ???
Hi I have:
unsigned int myvalue=0;
unsigned char mytest=0;

mytest=0x34;
myvalue = mytest<<24;

Then myvalue gets the value 0x1A000000!!!!!
How is this possible? Should''nt it be 0x34000000???




是的,它应该(并且在我的系统上,当然不能证明

任何东西)。

来自标准的


" 4 E1的结果<< E2是E1左移E2位位置;腾出的位

用零填充。如果E1具有无符号类型,则结果的值

为E1 x 2 ^ E2,比结果类型中可表示的最大值

减少一个模数。如果E1具有签名类型和非负值,并且E1 x

2 ^ E2在结果类型中可表示,那么这就是结果值;

否则,行为未定义。


我唯一的解释 - 除了你的

实际代码中的拼写错误(23而不是24),代码中的其他内容导致UB。我无法想象,

你的编译器在某种程度上被打破了。

你能发布一个显示错误的最小_compilable_程序吗?


Robert



Yes, it should (and is on my system, which of course doesn''t proof
anything).

from the standard:
"4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits
are filled with zeros. If E1 has an unsigned type, the value of the result
is E1 x 2^E2, reduced modulo one more than the maximum value representable
in the result type. If E1 has a signed type and nonnegative value, and E1 x
2^E2 is representable in the result type, then that is the resulting value;
otherwise, the behavior is undefined."

The only explanation I have - besides a typo (23 instead of 24) in your
actual code is something else in the code causing UB. I can''t imagine, that
your compiler is broken in _such_ a way.
Can you post a minimum _compilable_ program which exhibits the error?

Robert


也许你的编译器操作系统

我的VC + win32是对的,

myvalue = 0x34

" Jannick" < Ja*@janse.dk>在消息中写道

news:bm ********** @ news.net.uni-c.dk ...
maybe your compiler os OS
my VC+win32 is right,
myvalue=0x34

"Jannick" <Ja*@janse.dk> wrote in message
news:bm**********@news.net.uni-c.dk...
嗨我有:
unsigned int myvalue = 0;
unsigned char mytest = 0;

mytest = 0x34;
myvalue = mytest<< 24;
然后myvalue得到值0x1A000000 !!!!!
这怎么可能?不应该是0x34000000 ???

最好的问候
Jannick
Hi I have:
unsigned int myvalue=0;
unsigned char mytest=0;

mytest=0x34;
myvalue = mytest<<24;

Then myvalue gets the value 0x1A000000!!!!!
How is this possible? Should''nt it be 0x34000000???

Best Regards
Jannick



这篇关于最奇怪的问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆