0

A language has 28 different letters in total. Each word in the language is composed of maximum 7 letters. You want to create a data-type to store a word of this language. You decide to store the word as an array of letters. How many bits will you assign to the data-type to be able to store all kinds of words of the language.

Op 1: 7
Op 2: 35
Op 3: 28
Op 4: 196

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

With n bits, you can represent one of a set of 2**n characters, so 5 bits will be sufficient to represent one of the 28 characters in your set (2**5=32).

For each character in the string, you will need five bits, so a seven-character string will require 35 bits.

Note that you could map all 28^7 words onto 34 bits (ceiling(log(28^7)/log(2)) = 34), but I wouldn't recommend it.

kevin
  • 33
  • 5