Did You Know?
Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. This is because with 8 bits you can generate 256 different permutations.Check it yourself, click on the binary digits to create your own binary number:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
Python Challenge
The aim of this challenge is to write a procedure called listAllBinaryPermutations() that will take one parameter called numberOfBits and outputs all possible binary permutations depending on the number of bits.
For instance listAllBinaryPermutations(4) would output the following 16 binary permutations:
- 0000
- 0001
- 0010
- 0011
- 0100
- 0101
- 0110
- 0111
- 1000
- 1001
- 1010
- 1011
- 1100
- 1101
- 1110
- 1111
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area