How to create a decimal range of 24 bits?

I have 24 bits of binary code, which 111010001100001010011000 is equal to 15254168

I only guess at 24 bits because the binary length is 24.

I would like to generate all 24-bit decimal numbers programmatically. (C, PHP or Python)

2 ** 24 returns 16.777.216

So, there are 16.777.216 other decimal places (combinations). How can I generate them?

I can not understand the "range" of 24 bits. Can someone help me with this?

Thanks.

+5
source share
2 answers
<!-- language: python --> 

Is this what you want?

 >>> n = 3 >>> result = [bin(k)[2:].rjust(n, '0') for k in xrange(2**n)] >>> print result ['000', '001', '010', '011', '100', '101', '110', '111'] >>> n = 24 
+4
source

24 bits means that there are 24 bits (zeros or ones) that together create a binary number.

If you need all combinations or all numbers that can be expressed with 24 bits, this is just a range from 0 to 16777215. Why? here is a table in the format (binary = decimal):

 000000000000000000000000 = 0 000000000000000000000001 = 1 000000000000000000000010 = 2 000000000000000000000011 = 3 .... .... 111111111111111111111110 = 16777214 111111111111111111111111 = 16777215 

you really don't need to generate anything. You can check the binary for decimal: http://www.binaryhexconverter.com/binary-to-decimal-converter

Another thing: sometimes leading zeros are omitted in binary format. Thus, the decimal digit is not 000000000000000000000011, but rather equal to 11. If the length is 24 and the first digit is 1, its only range is 8388608 - 16777215

+2
source

All Articles