Click here to Skip to main content
15,902,198 members

Comments by Member 13765066 (Top 2 by date)

Member 13765066 5-Apr-18 22:54pm View    
If i explain it further;

For a small integer like 8, we take log base2 of 8. The result is 3, then we add 1 to 3 and the result is 4. So 4 bits are needed to represent 8.

For a large integer like 9223372036854775807, we take log base2 of 9223372036854775807. The result is 63. Here we don't need to add 1. It directly gives the number of bits, that is 63 bits are needed to represent 9223372036854775807.

In theory in python, it says that the number of bits needed to represent an integer n is given by rounding down log2(n) and then adding 1. But this seems not correct for a bigger integer?? This is what i couldnt understand.
Member 13765066 5-Apr-18 22:37pm View    
Deleted
Yes, but for a very very large integer, this is not practical.

If i explain it further;
For a small integer like 8, we take log base 2 of 8. The result is 3, then we add 1 to 3 and the result is 4. So 4 bits are needed to represent 8.

For a large integer like 9223372036854775807, we take log base 2 of 9223372036854775807. The result is 63. Here we don't need to add 1. It directly gives the number of bits, that is 63 bits are needed to represent 9223372036854775807.

In theory in python, it says that the number of bits needed to represent an integer n is given by rounding down log2(n) and then adding 1. But this seems not correct for a bigger integer??