Why can't tinyint store more than the number 255 in MySQL?
Asked Answered
G

2

5

If TINYINT can store three characters, for example, why can't it store up to the number 999?

Geothermal answered 24/2, 2010 at 18:18 Comment(1)
Actually, it can store up to 255, not 256, because 0 is also a value. Furthermore, if its signed, your range is cut up by half, meaning you can store from -128 up to 127.Popinjay
G
19

Because it takes only 8 bit and hence can encode no more than 2^8 = 256 values.

The three characters you see in something like '123' are the result of the binary to decimal conversion. You cannot store arbitrary 3 characters there.

Gurl answered 24/2, 2010 at 18:19 Comment(0)
I
4

It is 8 bits and can actually store a maximum value of 255. 8 bits have 256 possible states including zero.

Indeterminism answered 24/2, 2010 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.