windows 什么是ASCII码??
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15779778/
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
What is the ASCII Code of ??
提问by user2238999
I want to print the value '?' in a file. I searched for the ascii value of this as Alt+(ascii Value) will give you the same. To my surprise I found 2 ascii values for this symbol in various sites. One is 171 and the other is 189.
我想打印值 '?' 在一个文件中。我搜索了它的 ascii 值,因为 Alt+(ascii Value) 会给你同样的结果。令我惊讶的是,我在各个站点中发现了这个符号的 2 个 ascii 值。一个是 171,另一个是 189。
I tried to write this symbol by using 171 and 189. Again to my surprise, if I am writing in Windows, 171 will give me this symbol. But if I am writing in UNIX, 189 will give me this symbol.
我试着用 171 和 189 来写这个符号。再次让我惊讶的是,如果我在 Windows 中写,171 会给我这个符号。但是如果我用 UNIX 编写,189 会给我这个符号。
I was aware that there cant be 2 ASCII Values for a same symbol. But I got 2 valid codes for the same symbol in different OS. So can anyone tell what is the real ASCII Code for the symbol ? ??
我知道同一个符号不能有 2 个 ASCII 值。但是我在不同的操作系统中得到了相同符号的 2 个有效代码。那么谁能说出该符号的真正 ASCII 码是什么???
回答by Cody Gray
? is not a character in the ASCII character set.
? 不是ASCII 字符集中的字符。
The values you're finding online probably differ because they're using different character sets. For example, before Unicode was invented, localized versions of Windows all used different code pages, in which the basic ASCII set was extended with some additional characters.
您在网上找到的值可能不同,因为它们使用不同的字符集。例如,在发明 Unicode 之前,Windows 的本地化版本都使用不同的代码页,其中基本 ASCII 集被扩展了一些附加字符。
Now, of course, everything is (or should be) fully Unicode. Detailed Unicode information for that character (vulgar fraction one half) can be found here. Note that there are also multiple representationsfor the same numerical value (e.g., base 10, hex, binary, etc.).
现在,当然,一切都是(或应该)完全 Unicode。可以在此处找到该字符(粗俗分数二分之一)的详细 Unicode 信息。请注意,同一个数值也有多种表示形式(例如,基数为 10、十六进制、二进制等)。
回答by Basile Starynkevitch
Please read the ASCIIwikipedia page. You'll learn that ASCII has no "one half" character.
请阅读ASCII维基百科页面。您将了解到 ASCII 没有“二分之一”字符。
These days, most systems can be configured to use UTF-8encoding (which is the "default" or at least the most commonly used encoding on the Web and on Unix systems).
现在,大多数系统都可以配置为使用UTF-8编码(这是“默认”或至少是 Web 和 Unix 系统上最常用的编码)。
UTF-8 is a variable length encodingfor Unicode. So many characters or glyphs are represented by several bytes. For the ?
(officially the vulgar fraction one halfunicode character) its UTF8 encoding is the two hex bytes 0Xc2 0xBD so in C notation \302\275
UTF-8是一个编码的可变长度为Unicode的。这么多字符或字形由几个字节表示。对于?
(官方的粗俗分数二分之一unicode字符)它的UTF8编码是两个十六进制字节 0Xc2 0xBD 所以在C表示法中\302\275
I am using the Linux Gnome Character Map utility gucharmap
to find all that.
我正在使用 Linux Gnome 字符映射实用程序gucharmap
来查找所有这些。
You might be interested in UTF-32(a fixed length encoding using 32 bits characters, in which ? is represented by 0x000000BD), or even UTF-16in which many characters are 16 bits (in particular ?
is 0x00BD e.g. one 16 bit character in UTF-16), but not all. You may also be interested in wide charactersi.e. the wchar_t
of recent Cor C++standards (which is UTF-16 on Windows and UTF-32 on many Unix).
您可能对UTF-32(使用 32 位字符的固定长度编码,其中 ? 由 0x000000BD 表示)或什至UTF-16?
感兴趣,其中许多字符是 16 位(特别是 0x00BD,例如一个 16 位字符) UTF-16),但不是全部。您可能还对宽字符感兴趣,即wchar_t
最近的C或C++标准(在 Windows 上是 UTF-16,在许多 Unix 上是 UTF-32)。
FWIW, Qt is using QCharas UTF-16 (Java also has UTF-16 char
...), but Gtk use UTF-8 i.e. variable length characters.
FWIW,Qt 使用QChar作为 UTF-16(Java 也有 UTF-16 char
...),但 Gtk 使用 UTF-8,即可变长度字符。
Notice that with variable length character encodings like UTF-8 getting the N-th character (which is not the N-th byte!) in a string requires to scan the string. Also, some byte combinations are not valid UTF-8.
请注意,对于像 UTF-8 这样的可变长度字符编码,获取字符串中的第 N 个字符(不是第 N 个字节!)需要扫描字符串。此外,某些字节组合不是有效的 UTF-8。
回答by keV
In Windows if you use the ALT codes, 3 digits will insert the equivalent "Code page 850" character so ALT+ 171will insert the ? symbol
在 Windows 中,如果您使用 ALT 代码,则 3 位数字将插入等效的“代码页 850”字符,因此ALT+171将插入 ? 象征
189 is the ANSI/UTF-8/WIN-1252/ISO8859-1 value for the ? symbol. To use ALT codes for ANSI you MUST press 0first, so ALT+ 0189inserts the ? symbol
189 是 ANSI/UTF-8/WIN-1252/ISO8859-1 的值吗?象征。要对 ANSI 使用 ALT 代码,您必须先按0,所以ALT+0189插入 ? 象征
回答by Swift
I am quite sure that it is indeed part of the ASCII Table:
我很确定它确实是 ASCII 表的一部分:
In Windows, ensure 'NumLock' is on then try [ALT + (NumPAD)171] = ?. For ? use [ALT + 172]
在 Windows 中,确保“NumLock”打开,然后尝试 [ALT + (NumPAD)171] = ?。为了 ?使用 [ALT + 172]