位,整数表示 [英] bits, representations in integers

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

问题描述

你好


让我们假设CHAR_BIT == 8,sizeof(int)== 4和INT_MAX == 32767

('' d意味着int有32位,其中只有15位是值位。


现在,我的问题是,需要连续的值位是

表示?

签名位的位置是否固定(即最后一位,第一位

位)


甚至是最疯狂的表示,例如:(p =填充位,v =

值位,s =符号位)


pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv


是允许的?

Hello

Let''s assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that''d mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?
Is the position of the signed bit fixed (ie, the last bit, the first
bit)

Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?

推荐答案

vi ****** @ gmail.com 写道:

你好


让我们假设CHAR_BIT == 8,sizeof(int)== 4和INT_MAX == 32767

(这意味着int有32位,其中只有15位是值位)


现在,我的问题是,是v在表示中需要连续的位数?
表示?
Hello

Let''s assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that''d mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?



编号6.2.6.1:所有类型的陈述均未指明

,除非本条款另有说明,并且子条款没有说明关于如何排列的

No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.


签名位的位置是否固定(即最后一位) ,第一个

位)
Is the position of the signed bit fixed (ie, the last bit, the first
bit)



编号

No.


甚至是最疯狂的表示,例如:(p =填充位,v =

值位,s =符号位)


pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv


是允许的吗?
Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?



当然。请注意,您不能看到一个字节的各个位

与它们所代表的值隔离开来。您可能能够通过实验确定指定值位占用哪个字节

(尽管在存在填充位的情况下即使这很多也是如此)

,你的设置是你无法控制的),但那是关于所有的。


-
Er ********* @ sun.com


10月9日晚上8:20 ,Eric Sosman< Eric.Sos ... @ sun.comwrote:

消息ID:< 1223572818.225547@news1nwk>


谢谢。
On Oct 9, 8:20 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
Message-ID: <1223572818.225547@news1nwk>

Thanks.


Eric Sosman< Er ********* @ sun.comwrites:
Eric Sosman <Er*********@sun.comwrites:
vi ****** @ gmail.com 写道:

> Hello

让我们假设CHAR_BIT == 8,sizeof(int)== 4和INT_MAX == 32767
(这意味着int有32位,其中只有15位是值位)

现在,我的问题是,是否需要在
>Hello

Let''s assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that''d mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?



编号6.2.6.1:所有类型的陈述均未指明

,除非本条款另有说明,并且子条款没有说明关于位如何排列的


No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.



但是,在某些方面,编译器必须表现得好像它们是连续的
。例如,


int a,b;

a = 1;

b = a<< 1;

根据6.5.7,
b必须给出值2.

However, in some ways the compiler has to behave as if they are
contiguous. For instance, in

int a,b;
a=1;
b = a << 1;

b must be given the value 2, according to 6.5.7.


>签名位的位置是固定的(即最后一位,第一位
位)
>Is the position of the signed bit fixed (ie, the last bit, the first
bit)



No.


No.


>或者甚至是最疯狂的表示,例如:(p =填充位,v =
值位,s =符号位)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv
是允许的吗?
>Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?



当然。请注意,您不能看到一个字节的各个位

与它们所代表的值隔离开来。您可能能够通过实验确定指定值位占用哪个字节

(尽管在存在填充位的情况下即使这很多也是如此)

,你的设置是你无法控制的),但这就是全部。


Sure. Note that you cannot "see" the individual bits of a byte
in isolation from the value that they represent. You might be able
to determine by experiment which byte a specified value bit occupies
(though even this much is chancy in the presence of padding bits
whose settings you do not control), but that''s about all.



注意,在这种情况下,编译器必须实现<<和>>

运算符相当复杂。

Note in this case the compiler would have to implement the << and >>
operators in a rather complicated manner.


这篇关于位,整数表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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