首先可以确定的告诉你,
C/C++的标准中,从来没有规定1byte等于8bit
.它只规定了:sizeof(char) = 1,除此之外,还有一项相关的规定就是:sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long).
但是现实中,1byte确实绝大部分都是8bit的.其源头是tcp/ip协议中,有这样的规定.
所以,除非你做的系统不准备支持tcp/ip协议,否则,依循它的协议,使用1byte=8bit是最简单的.ps:
我完整的帖一下c/c++标准中对相关概念的定义吧,以c99为例(其他版本和c++的都类似):
3.51 bit
unit of data storage in the execution environment large enough to hold an object that may
have one of two values
2 NOTE It need not be possible to express the address of each individual bit of an object.
3.61 byte
addressable unit of data storage large enough to hold any member of the basic character
set of the execution environment
2 NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
3 NOTE 2 A byte is composed of a contiguous sequence of bits,
the number of which is implementation-de