y>> (8 *(sizeof(int)-1)) [英] y >> (8 * (sizeof(int) -1))

查看:56
本文介绍了y>> (8 *(sizeof(int)-1))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是y>(8 *(sizeof(int)-1))可移动表达式要找到的MSB

无符号整数y ??


将在所有情况下都有效,所有三种表示形式都允许:


1)两个'补充说明

2)''''''''''$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

> aa*****@gmail.com 写道:


是y>(8 *(sizeof(int)-1))可移动表达式查找

的MSB无符号整数y ??



可能更好,更便携:

#include< limits.h>

....

y>(CHAR_BIT *(sizeof y -1))


这将适用于所有情况,所有三个表示C

允许:


1)两个补码

2)一个''实现

3)签名幅度。



再见,Jojo


2008年4月15日星期二09:47:15 -0700,aarklon写道:


是y>(8 *(sizeof(int)-1))可移动表达式查找

的MSB无符号整数y ??



不,它不是。


这将适用于所有情况,全部三个的陈述C

允许:


1)两个补码

2)一个''补充
3)签名幅度。



这些与负值的表示方式不同。为什么你认为

负值很重要,因为你有一个无符号整数?


aark ... @ gmail.com写道:


是y>(8 *(sizeof(int)-1))可移动表达式找到的MSB

an无符号整数y ??



在以下情况下定义MSB ...


CHAR_BIT = 8

UINT_MAX = 262143


如果你想要一个无符号的顶部CHAR_BIT位,请使用...

$ b $ /((UINT_MAX>(CHAR_BIT) - 1)> 1)+ 1)


这将适用于所有情况,所有三个表示形式C

允许:


1)两个补码

2)一个''实现

3)签名幅度。



无符号整数使用纯二进制表示。


-

彼得



Is y >(8 * (sizeof(int) -1)) portable expression to find The MSB of
an unsigned integer y ??

will this work in all the cases, all three of the representations C
allows:

1) two''s complement
2) ones''complement
3) signed magnitude.

解决方案

aa*****@gmail.com wrote:

Is y >(8 * (sizeof(int) -1)) portable expression to find The MSB of
an unsigned integer y ??

Probably better and more portable:
#include <limits.h>
....
y >(CHAR_BIT * (sizeof y -1))

will this work in all the cases, all three of the representations C
allows:

1) two''s complement
2) ones''complement
3) signed magnitude.

Bye, Jojo


On Tue, 15 Apr 2008 09:47:15 -0700, aarklon wrote:

Is y >(8 * (sizeof(int) -1)) portable expression to find The MSB of
an unsigned integer y ??

No, it isn''t.

will this work in all the cases, all three of the representations C
allows:

1) two''s complement
2) ones''complement
3) signed magnitude.

These differ in how negative values are represented. Why do you think
negative values matter, given that you''ve got an unsigned integer?


aark...@gmail.com wrote:

Is y >(8 * (sizeof(int) -1)) portable expression to find The MSB of
an unsigned integer y ??

Define MSB in the following case...

CHAR_BIT = 8
UINT_MAX = 262143

If you want the top CHAR_BIT bits from an unsigned int y, use...

y / ((UINT_MAX >(CHAR_BIT - 1) >1) + 1)

will this work in all the cases, all three of the representations C
allows:

1) two''s complement
2) ones''complement
3) signed magnitude.

Unsigned integers use pure binary representation.

--
Peter


这篇关于y&gt;&gt; (8 *(sizeof(int)-1))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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