本文介绍了ASCII表和字符表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在课堂上学习了ASCII表,并且128个字符中的每个字符都有一个从0-128的唯一数字来表示它.例如,"a"为97(二进制97中为1100001).%"为37(二进制37为0100101). (我知道对于固定长度7,我们应该允许二进制数字以0开头)

We learn in class about ASCII table, and that every character from 128 characters has a unique number from 0-128 representing it.For example "a" is 97 (in binary 97 is 1100001)."%" is 37 (and in binary 37 is 0100101). (I understand that for a fixed length of 7 we should allow the binary number start with 0)

如果97代表"a",那么代表字符串"97"的是什么?什么代表整数97?

If 97 is representing "a", then what represents the string "97"? What represents the integer 97?

推荐答案

我认为您的问题基于以下观念:给定整数,字符串或其他类型的值的表示形式,您可以确定类型和值.你不能

I think your question is based on the notion that, given a representation of an integer, string or other type of value, you can decern the type and the value. You can't.

在大多数数字计算机体系结构中,数据是位,以连续的8位字节进行访问.您可以获取一个字节,将其视为非负整数,然后将其表示为二进制,八进制,十进制,十六进制等.当一个位本身代表一个值时,将使用二进制.十六进制是首选,因为它的紧凑性和易于转换为二进制格式.当整个字节对人类具有一些基数值时,将使用十进制,这使其成为负整数的选择.

In most digital computer architectures, data is bits, accessed in contiguous 8-bit bytes. You can take a byte, think of it as a non-negative integer, and represent it in binary, octal, decimal, hexadecimal, …. Binary is used when a bit represents a value by itself. Hexadecimal is preferred for its compactness and easy translation to binary. Decimal is used when the whole byte has some cardinal number value to humans, which makes it the choice for negative integers.

因此,给定一个字节(97)(十进制),例如来自1字节文件或位于内存地址的字节,类型和值是什么?唯一的了解方法是通过某种共同的理解:协议,声明,约定,规范,数据映射等.换句话说,就是 communication .完整的通信包含数据以及指示如何解释字节的随附或单独的元数据.

So, given the byte, 97 (decimal), say from a 1-byte file or at a memory address, what's the type and value? The only way to know is through some sort of shared understanding: an agreement, declaration, convention, specification, data map, etc. In other words, communication. Complete communication consists of the data and accompanying or separate metadata that indicates how to interpret the bytes.

97₁₀=61₁₆=01100001²是:

97₁₀ = 61₁₆ = 01100001₂ could be:

  • 作为8位无符号整数:97₁₀
  • 作为8位二进制补码有符号整数:97₁₀
  • 作为UTF-8代码单元:碰巧是Unicode代码点的所有代码单元:'a'(U + 0061)'拉丁文小写字母A'
  • 作为ASCII代码单位:(所有ASCII代码点均采用一个8位代码单位):"a"
  • 作为ISO 8859-1代码单位:(所有ISO 8859-1代码点均采用一个8位代码单位):'a'
  • 可以打包成8位的所有内容.
  • As an 8-bit unsigned integer: 97₁₀
  • As an 8-bit two's complement signed integer: 97₁₀
  • As a UTF-8 code unit: happens to be all the code units for the Unicode codepoint: 'a' (U+0061) 'LATIN SMALL LETTER A'
  • As an ASCII code unit: (all ASCII codepoints take one 8-bit code unit): 'a'
  • As an ISO 8859-1 code unit: (all ISO 8859-1 codepoints take one 8-bit code unit): 'a'
  • Anything at all that can be packed into 8 bits.

因此,将您的问题改写为:代表"a"的97和代表整数97的97有什么区别?答案在元数据中,而不是字节中.

So, rephrasing your question as: What's the difference 97 representing "a" and 97 representing the integer 97? The answer is in the metadata, not the bytes.

这篇关于ASCII表和字符表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 18:11