一个字节和int的大小? [英] size of a byte and int?

查看:167
本文介绍了一个字节和int的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


那个字节的大小不一定是8位吗?

什么是std。说?如果这是真的,那么int的大小是什么,

i意味着sizeof(int)应该返回什么?


在我的机器上sizeof(char)= = sizeof(int)。

TMS320C5402 DSP(16位字大小)。

都返回一个。所以,它是正确的。


但我的解释是:

int,float等的大小是以字节而不是位来指定的...是一个

标准,即int - > 2个字节,char - > 1字节等...现在,这些

的实际大小取决于否。字节中的位数...是实现定义的。所以,

如果我们在机器上说它定义的1字节= 8位然后大小(char)= 1byte =

8位大小(int)= 2字节= 16位...

但在其他机器上1字节= 16位大小(字符)= 1byte = 16位和

大小(Int)= 2字节= 32位。在任何情况下,对于char和amp;都可以是相同的。 int。


请帮我解决我失踪的问题。


-Neo

Hi All,

Is that true that size of a byte not necessarily 8-bit?
What the std. says? If that true, then what will the size of an int,
i mean what sizeof(int) should return?

On my machine sizeof(char) == sizeof(int).
TMS320C5402 DSP (with 16-bit word size).
both returns one. So, it holds true.

But my interpretation is :
Size of int,float etc is specified in terms of bytes, not bits...which is a
standard i.e int -> 2 bytes, char -> 1 byte etc... now, actual size of these
depends up on no. of bits in a byte... which is implementation defined. So,
if we say on a machine its defined 1 byte = 8 bits then size(char) = 1byte =
8 bits size(int) = 2 bytes = 16 bits...
but on other machine 1 byte = 16 bits the size(char) = 1byte = 16 bits and
Size(Int) =2 bytes= 32 bits. In no case, it can be same for both char & int.

Please help me where I am missing.

-Neo

推荐答案

Neo写道:

大家好,

这是真的,一个字节的大小不一定是8位?

Hi All,

Is that true that size of a byte not necessarily 8-bit?




宽度以位为单位。

大小以字节为单位。


- -

pete



Width is measured in bits.
Size is measured in bytes.

--
pete




" pete" < PF ***** @ mindspring.com>在消息中写道

news:41 *********** @ mindspring.com ...

"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com...
Neo写道:
大家好,

那个字节的大小不一定是8位吗?

Hi All,

Is that true that size of a byte not necessarily 8-bit?



宽度以位为单位测量。 />大小以字节为单位。

-
pete



Width is measured in bits.
Size is measured in bytes.

--
pete




O''kay!测量int和char(C中的数据类型)是什么?

-Neo



O''kay! What does int and char (data types in C) are measured in?
-Neo


Neo写道:

那个字节的大小不一定是8位吗?


是的。

std。说?


它表示一个字节的宽度为CHAR_BIT位,其中CHAR_BIT> = 8.

如果为真,那么int的大小是多少,
我的意思是sizeof(int)应该返回什么?


它将是给定实现的任何内容。

在我的机器上sizeof(char)== sizeof(int)。
TMS320C5402 DSP(16位字大小)。
都返回一个。所以,它是成立的。

但我的解释是:
int,float等的大小是以字节而不是位来指定的......


编号整数和浮点数是根据价值限制指定

和精度。 signed int必须能够表示的最小范围是/ b
来表示-32767..32767。数学要求这个

至少需要16位(包括一个符号位)。因此,

int将需要_at至少所需的字节数

存储16位。

请帮我解决我失踪的问题。

Is that true that size of a byte not necessarily 8-bit?
Yes.
What the std. says?
It says that a byte is CHAR_BIT bits in width, where CHAR_BIT >= 8.
If that true, then what will the size of an int,
i mean what sizeof(int) should return?
It will be whatever it is on a given implementation.
On my machine sizeof(char) == sizeof(int).
TMS320C5402 DSP (with 16-bit word size).
both returns one. So, it holds true.

But my interpretation is :
Size of int,float etc is specified in terms of bytes, not bits...
No. Integers and floats are specified in terms of value limits
and precision. The minimum range that a signed int must be able
to represent is -32767..32767. Mathematics dictate that this
requires at least 16 bits (including a sign bit.) Thus, an
int will require _at least_ as many bytes as is required to
store 16-bits.
Please help me where I am missing.




Google for N869并阅读最后一次公开C99标准草案。

-

彼得



Google for N869 and read the last public draft of the C99 standard.
--
Peter


这篇关于一个字节和int的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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