How many characters can you store with 1 byte?

MysqlCharacterByte

Mysql Problem Overview


1 byte = 8 bits 

So, does this mean 1 byte can only hold one character? E.g.:

"16" uses 2 bytes , "9" uses 1 byte , "a" uses 1 byte, "b" uses 1 byte 

and if tiny int has range of 0-255, does this mean it can be stored with 255 char?

what is storage of

1. tiny int (1)
2. tiny int (2) 

what will be the range 0-10

Mysql Solutions


Solution 1 - Mysql

1 byte may hold 1 character. For Example: Refer Ascii values for each character & convert into binary. This is how it works.

enter image description here value 255 is stored as (11111111) base 2. Visit this link for knowing more about binary conversion. http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html

Size of Tiny Int = 1 Byte ( -128 to 127)

Int = 4 Bytes (-2147483648 to 2147483647)

Solution 2 - Mysql

Yes, 1 byte does encode a character (inc spaces etc) from the ASCII set. However in data units assigned to character encoding it can and often requires in practice up to 4 bytes. This is because English is not the only character set. And even in English documents other languages and characters are often represented. The numbers of these are very many and there are very many other encoding sets, which you may have heard of e.g. BIG-5, UTF-8, UTF-32. Most computers now allow for these uses and ensure the least amount of garbled text (which usually means a missing encoding set.) 4 bytes is enough to cover these possible encodings. I byte per character does not allow for this and in use it is larger often 4 bytes per possible character for all encodings, not just ASCII. The final character may only need a byte to function or be represented on screen, but requires 4 bytes to be located in the rather vast global encoding "works".

Solution 3 - Mysql

2^8 = 256 Characters. A character in binary is a series of 8 ( 0 or 1).

   |----------------------------------------------------------|
   |                                                          |
   | Type    | Storage |  Minimum Value    | Maximum Value    |
   |         | (Bytes) | (Signed/Unsigned) | (Signed/Unsigned)|
   |         |         |                   |                  |
   |---------|---------|-------------------|------------------|
   |         |         |                   |                  |
   |         |         |                   |                  |
   | TINYINT |  1      |      -128 - 0     |  127 - 255       |
   |         |         |                   |                  |
   |----------------------------------------------------------|

Solution 4 - Mysql

The syntax of TINYINT data type is TINYINT(M),

where M indicates the maximum display width (used only if your MySQL client supports it).

> The (m) indicates the column width in SELECT statements; however, it > doesn't control the accepted range of numbers for that field.

>A TINYINT is an 8-bit integer value, a BIT field can store between 1 bit, BIT(1), and 64 >bits, BIT(64). For a boolean values, BIT(1) is pretty common.

TINYINT()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbhi AdrView Question on Stackoverflow
Solution 1 - MysqlVenkatesh KView Answer on Stackoverflow
Solution 2 - MysqlRod LloydView Answer on Stackoverflow
Solution 3 - MysqlKiran RSView Answer on Stackoverflow
Solution 4 - MysqlAmarnath BalasubramanianView Answer on Stackoverflow