10

I've seen lots of places say:

The maximum number of characters is 255.

where characters are ASCII. Is there a technical reason for that?

EDIT: I know ASCII is represented by 8 bits and so there're 256 different characters. The question is why do they specify the maximum NUMBER of characters (with duplicates) is 255.

dazzphot
  • 307
  • 1
  • 3
  • 11
  • Please keep in mind that there is no one character set called "extended ASCII". It is very important to say exactly which one (e.g., CP437 and Windows-1252). – Tom Blodget Oct 05 '14 at 02:26
  • 1
    Not sure where that claim came from, but might have something to do with the C language treating 0 as a string terminator. – Hans Passant Oct 05 '14 at 02:26
  • 2
    Whatever the answer, the statement above about 255 characters in ASCII is wrong. It forgets the 00h valued octet, it uses the extended ASCII set, and forgets about holes (unmapped bytes) in the ASCII character set. This kind of comments are usually put where people don't understand the difference between bytes, text and null-terminated `char*` values. Proceed with care if you find statements like these and expect anything (especially bugs and buffer overruns). – Maarten Bodewes Oct 05 '14 at 14:05

5 Answers5

14

I assume the limit you're referring to is on the length of a string of ASCII characters.

The limit occurs due to an optimization technique where smaller strings are stored with the first byte holding the length of the string. Since a byte can only hold 256 different values, the maximum string length would be 255 since the first byte was reserved for storing the length.

Some older database systems and programming languages therefore had this restriction on their native string types.

Community
  • 1
  • 1
Silveri
  • 4,836
  • 3
  • 35
  • 44
  • I think the question was referring to strings, not characters, and this is the best answer. I noticed that in some databases, the default string limit is 255 characters for some text data types. – Victor Stoddard Feb 11 '20 at 22:54
  • 1
    "Some older database systems and programming languages therefore had this restriction on their native string types." Aaand the file explorer paths in Windows 10 -.- Fascinating that this is not fixed yet. – Anton Feb 10 '22 at 15:47
12

Extended ASCII is an 8-bit character set. (Original ASCII is 7-bit, but that's not relevant here.)

8 bit means that 2^8 different characters can be referenced.

2^8 equals 256, and as counting starts with 0, the maximum ASCII char code has the value 255.

Thus, the statement:

The maximum number of characters is 255.

is wrong, it should read:

The maximum number of characters is 256, the highest possible character code is 255.

To understand better how characters are mapped to the numbers from 0 to 255, see the 8-bit ASCII table.

lxg
  • 12,375
  • 12
  • 51
  • 73
  • The introductory text of the page that you link says it's not ASCII. Also note that the table lists fewer than 256 characters. – Tom Blodget Oct 05 '14 at 02:24
  • @TomBlodget: Huh? Of course it's ASCII, it's written all over the page. Where do you see a note that it's not ASCII? And, there are 256 (0 - 255) symbols, exactly as I said. – lxg Oct 05 '14 at 07:28
  • 1
    "On this webpage you will find 8 bits, 256 characters, according to ISO 8859-1 and Microsoft® Windows Latin-1." So it is one of many ["Extended ASCII"](http://en.wikipedia.org/wiki/Extended_ASCII#Character_set_confusion) character sets. When dealing with character sets and encodings, it essential to say which one, either by name or by referring to the thread/process/user/OS default. It looks like [Windows-1252](http://en.wikipedia.org/wiki/Windows-1252). I didn't check the whole table but I did check the holes at 81, 8D, 8F, 90, 9D. – Tom Blodget Oct 05 '14 at 13:33
  • @TomBlodget: Ok, I get your point. :) My answer indeed oversimplifies things, but I think it's sufficient to answer the original question. Thanks for your annotations, though. – lxg Oct 05 '14 at 14:50
2

the limit is 255 because 9+36+84+126 = 255. the 256th character (which is really the first character) is zero.

using the combinatoric formula Ck(n) = n/k = n!/(k!(n-k)!) to find the number of non-repeating combinations for 1,2,3,4,5,6,7,8 digits you get this:

of digits: 1 2 3 4 5 6 7 8

of combinations: 9 36 84 126 126 84 36 9

it is unnecessary to include 5-8 digits since it's a symmetric group of M. in other words, a 4 element generator is a group operation for an octet and its group action has 255 permutations.

interestingly, it only requires 3 digits to "count" to 1000 (after 789 the rest of the numbers are repetitions of previous combinations).

Community
  • 1
  • 1
RNH
  • 21
  • 2
2

The 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).

The ASCII value of a-z  =  97-122
The ASCII value of A-Z  =  65-90
The ASCII value of 0-9  =  48-57
1

Is there a technical reason for that?

Yes there is. Early ASCII encoding standard is 7 bit log, which can represent 2^7 = 128 (0 .. 127) different character codes.

What you are talking about here is a variant of ASCII encoding developed later, which is 8 bit log and can hold 2^8 = 256 (0 .. 255) character codes.

See Wikipedia for more information on the same.

Rahul
  • 76,197
  • 13
  • 71
  • 125