MySQL 1个字节可以存储多少个字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21300929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How many characters can you store with 1 byte?
提问by Abhi Adr
1 byte = 8 bits
So, does this mean 1 byte can only hold one character? E.g.:
那么,这是否意味着 1 个字节只能容纳一个字符?例如:
"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?
如果tiny int
范围为 0-255,这是否意味着它可以存储 255 个字符?
what is storage of
什么是存储
1. tiny int (1)
2. tiny int (2)
what will be the range 0-10
会是什么 range 0-10
回答by Venkatesh K
1 byte may hold 1 character. For Example: Refer Ascii values for each character & convert into binary. This is how it works.
1 个字节可以容纳 1 个字符。例如:为每个字符参考 Ascii 值并转换为二进制。这就是它的工作原理。
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
值 255 存储为 (11111111) base 2。访问此链接以了解有关二进制转换的更多信息。
http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html
Size of Tiny Int = 1 Byte ( -128 to 127)
Tiny Int 的大小 = 1 字节(-128 到 127)
Int = 4 Bytes (-2147483648 to 2147483647)
Int = 4 字节(-2147483648 到 2147483647)
回答by Rod Lloyd
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".
是的,1 个字节确实编码了 ASCII 集中的一个字符(包括空格等)。然而,在分配给字符编码的数据单元中,它实际上可以并且经常需要多达 4 个字节。这是因为英语不是唯一的字符集。即使在英文文档中,也经常使用其他语言和字符。它们的数量非常多,还有许多其他编码集,您可能听说过,例如 BIG-5、UTF-8、UTF-32。大多数计算机现在允许这些用途并确保最少的乱码文本(这通常意味着缺少编码集)。4 个字节足以涵盖这些可能的编码。I byte per character 不允许这样做,并且在使用中,对于所有编码,而不仅仅是 ASCII,每个可能的字符通常为 4 个字节。最后一个字符可能只需要一个字节即可运行或在屏幕上显示,
回答by Amarnath Balasubramanian
The syntax of TINYINT
data type is TINYINT(M)
,
TINYINT
数据类型的语法是TINYINT(M)
,
where M
indicates the maximum display width (used only if your MySQL client supports it).
whereM
表示最大显示宽度(仅在您的 MySQL 客户端支持时使用)。
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.
(m) 表示 SELECT 语句中的列宽;但是,它不控制该字段可接受的数字范围。
TINYINT 是一个 8 位整数值,一个 BIT 字段可以存储 1 位 BIT(1) 和 64 > 位 BIT(64)。对于布尔值,BIT(1) 很常见。
回答by Kiran RS
2^8 = 256 Characters. A character in binary is a series of 8 ( 0 or 1).
2^8 = 256 个字符。二进制字符是一系列 8(0 或 1)。
|----------------------------------------------------------|
| |
| Type | Storage | Minimum Value | Maximum Value |
| | (Bytes) | (Signed/Unsigned) | (Signed/Unsigned)|
| | | | |
|---------|---------|-------------------|------------------|
| | | | |
| | | | |
| TINYINT | 1 | -128 - 0 | 127 - 255 |
| | | | |
|----------------------------------------------------------|