68
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

Ricardo
  • 3,696
  • 5
  • 36
  • 50
Abhi Adr
  • 1,264
  • 2
  • 11
  • 27

4 Answers4

69

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)

Venkatesh K
  • 4,364
  • 4
  • 18
  • 26
  • 3
    While an 8-bit byte holds exactly one 8-bit character, if you are working with a subset of characters they can be encoded into less than 8 bits. For instance, as one example, if you *only* wanted to store uppercase letters A-Z, you could store up to 9 of them in one byte. This in practice is really rare, and generally one requires more than just A-Z (and even if one doesn't at time of implementation, one will in the future). Space is cheap these days and so we generally don't stoop to this sort of encoding which is frankly nasty in terms of how fiddly it can get to code with. – Brian C Sep 12 '19 at 02:39
9

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".

Rod Lloyd
  • 91
  • 1
  • 1
  • Your points are valid but I think you are confusing the English alphabet with [English letters](https://english.stackexchange.com/questions/41321/is-the-word-formul%C3%A6-valid-english/80397#80397). (I think English is somewhat unique in that "The Alphabet" does not list all of its letters, let alone all computerized character forms of them.) – Tom Blodget Jun 24 '19 at 02:32
1

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       |
   |         |         |                   |                  |
   |----------------------------------------------------------|
Kiran RS
  • 981
  • 14
  • 31
  • 22
    I believe there's confusion that 1 byte can hold 256 a count of characters -- it cannot, but rather that 1 character can have 256 options/variations/characters (a,b,c,or...) - if the character only uses up 1 byte. If it requires more bytes such as unicode then it would allow for more character options, which unicode of course requires. Just like how 1 byte can hold 256 "options" you can store any single number between 0 and 255 in 1 byte as a single number, but that doesn't mean that you get 255 different numbers. – CTS_AE Nov 23 '14 at 09:12
0

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()

Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62