What does 256 means for 128 unique characters in ascii table

Lydia picture Lydia · Dec 28, 2014 · Viewed 62.8k times · Source

If I need to check a string has unique characters, I understand if we are considering characters in Ascii table, then there will 128 of them.

However, why do we need to make a boolean array of size 256 to hold 128 characters to check if element existed at least once in a string? Shouldn't a boolean array of size 128 sufficient?

Here's a quote from from the book "Cracking the Coding Interview":

if (str.length() > 128) return false;
boolean[] char_set = new boolean[256]; //which is strange since it clearly says over 128 its false

.....

Answer

MOHIT M SHARMA picture MOHIT M SHARMA · Jul 20, 2016

Basically, we use only 128 total character which is used mostly during program. But total number of Character in ASCII table is 256 (0 to 255). 0 to 31(total 32 character ) is called as ASCII control characters (character code 0-31). 32 to 127 character is called as ASCII printable characters (character code 32-127). 128 to 255 is called as The extended ASCII codes (character code 128-255).

check reference: http://www.ascii-code.com/

Most of the extended ASCII character isn't present in the QWERTY (ENGLISH) keyboard, so this is the reason, author took 128 total character in that example in "Cracking the coding interview" book.