0

How can I know the number of bits a byte has in C++? Is there a function similar to sizeof?

Thank you.

  • 2
    There is not byte, but there is `char`, whose bit-size is defined by `CHAR_BIT`..... – Oliver Charlesworth Mar 14 '15 at 11:40
  • Byte always has 8 bits. You meant int? – Andrei Smeltsov Mar 14 '15 at 11:41
  • @OliverCharlesworth: The "byte" is defined in the C++ standard, it is the size of a `char` by definition. – Dietrich Epp Mar 14 '15 at 11:42
  • 2
    @RaccoonMonk: You would think. There are systems where this is not the case. Most of them are only of historical interest. – Dietrich Epp Mar 14 '15 at 11:42
  • @DietrichEpp: Ah, I was thinking of C. Thanks for correcting. – Oliver Charlesworth Mar 14 '15 at 11:42
  • @OliverCharlesworth: It is also defined in C. Refer to section 3, "Terms, definitions, and symbols". – Dietrich Epp Mar 14 '15 at 11:43
  • 1
    @OliverCharlesworth That's what I needed. Of course I am using chars as bytes. And guys, in C++ a byte is not always 8 bits. –  Mar 14 '15 at 11:43
  • 2
    @RaccoonMonk, a byte is *not* always 8 bit, you mean an octet. There are CPUs out there where a byte has more or less bits. – Ulrich Eckhardt Mar 14 '15 at 11:44
  • 1
    @RaccoonMonk [Is a byte always 8 bits?](https://stackoverflow.com/questions/13615764/is-a-byte-always-8-bits) No, have a look at the list of [System where 1 byte != 8 bit?](https://stackoverflow.com/questions/5516044/system-where-1-byte-8-bit) here. A [byte](https://en.wikipedia.org/wiki/Byte) was never been always 8 bits, an **octet** is – phuclv Mar 14 '15 at 12:54

0 Answers0