Quote:
Originally Posted by Arco.
No. After discussing this with Evan, we both agree you are wrong. A byte in C++ is a uchar. And another part where you're wrong, UInt8 would be the correct typecast for it.
|
True. The 'Byte' in C# is the equivalent of the 'unsigned char' if we consider that a char is implemented as a 8 bits integer.
Anyway, a byte is an integer of any size. Some implementations say that a byte is an integer of 9 bits, some others say that it's 7 bits. To avoid confusion, the C99/POSIX standard implemented the (u)intN_t definitions where it's an (un)signed N bits integer. It's not true to say that a byte is a UInt8. As we shouldn't say that an ushort is a UInt16 as a short is suppose to be at least 16 bits. When defining structure, you should use type name based on the number of bits. And you shouldn't say the number of bytes of a file, but the number of octets as an octets is defined as an 8 bits integer. You should avoid using keywords as short/int/word/byte/etc because they are all dependent of the implementation. They aren't fixed-size integer as the C99/POSIX standard.
So, to be compliant to any language, any implementation.
(U)IntN is the solution ;)
Oh, and to give a good definition for the range of a N bits integer.
Signed: [-2^(N-1), 2^(N-1) - 1]
Unsigned: [0, 2^N - 1]