0

How to obtain bits from a data type on C++?

I want to know if there is some library where I can obtain the bits from an int or unsigned char or any data type. I know that I can use sizeof (), but that returns in bytes, is there a function where do the same work that sizeof() but returning the result in bits? I don't want to obtain a bunch of 0s and 1s, a char is 8 bits, int 32 and so on... I cannot find a function where returns in bits.

19th Jan 2019, 1:39 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
1 ответ
+ 1
If sizeof returns the size in bytes, and one byte has 8 bits, then: bits = 8*sizeof(x)
19th Jan 2019, 1:52 AM
voidneo