Reputation: 91
The sizeof(data_type)
operator returns the number of bytes and not octets, so the size of a byte may not be 8 bits. How can one identify the size of a byte in bits on any platform?
Upvotes: 1
Views: 153
Reputation: 6771
A byte is commonly 8 bits independent of the platform (edited based on comment below). Else you could do:
int
) to -1
.sizeof(int)
, if you used an int
).Upvotes: 0
Reputation: 2420
I think you can do sizeof(type) * CHAR_BIT
to determine the number of bits. Include limits.h for the definition of CHAR_BIT.
Upvotes: 4