We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Alphabet Formula

The number of total characters in an alphabet depends on how many bits each character in an encoded string can represent.

  • 1 bit -> 2 chars (0 and 1, binary)
  • 2 bits -> 4 chars
  • 4 bits -> 16 chars (i.e. hexadecimal)
  • 7 bits -> 128 chars (i.e. ASCII)
  • 8 bits -> 256 chars

Notice how the number of characters grows exponentially based on the number of bits. The number of characters is equal to the number of combinations that can be created by the individual bits.

2-Bit Example

00 = char 0
01 = char 1
10 = char 2
11 = char 3

So with 2 bits, we can represent 4 characters in total.

Assignment

Complete the alphabetSize() function. It accepts a number of bits per character as input, and returns the size of the alphabet that can be represented by that number of bits.