简体   繁体   English

Octet String是什么意思? Octet和Char有什么区别?

[英]What is meant by Octet String? What's the difference between Octet and Char?

What is the difference between octet string and char? octet string和char有什么区别? How can an octet string be used? 如何使用八位字符串? Can anybody write a small C program on Octet string? 任何人都可以在Octet字符串上写一个小C程序吗? How are octet strings stored in memory? 八位字符串如何存储在内存中?

Standards (and such) use "octet" to explicitly state that they're talking about 8-bit groups. 标准(等)使用“八位字节”明确表明他们正在谈论8位组。 While most current computers work with bytes that are also 8 bits in size, that's not necessarily the case. 虽然大多数当前的计算机使用的字节大小也是8位,但情况并非如此。 In fact, "byte" is rather poorly defined, with considerable disagreement over what it means for sure -- so it's generally avoided when precision is needed. 事实上,“字节”的定义相当不明确,对于它确实意味着什么存在相当大的分歧 - 因此在需要精度时通常会避免这种情况。

Nonetheless, on a typical computer, an octet is going to be the same thing as a byte, and an octet stream will be stored in a series of bytes. 尽管如此,在典型的计算机上,八位字节与字节相同,八位字节流将以一系列字节存储。

  • An octet is another word for a 8-bit byte. 八位字节是8位字节的另一个字。
  • A char is usually 8 bits, but may be another size on some architectures. char通常是8位,但在某些体系结构上可能是另一个大小。

An octet is 8 bits meant to be handled together (hence the "oct" in "octet"). 八位字节是8位意味着要一起处理(因此“八位字节”中的“oct”)。 It's what we think of when we say "byte" these days. 这就是我们这些天说“字节”时的想法。

A char is basically a byte -- it's defined as the smallest addressable unit of memory, which on almost all modern computers is the same as an octet. char基本上是一个字节 - 它被定义为内存的最小可寻址单元,几乎在所有现代计算机上都与八位字节相同。 But there have been computers with 9-bit, 16-bit, even 36-bit "words" that qualify as chars by that definition. 但是有一些计算机具有9位,16位,甚至36位“字”,这些字符符合该定义的字符。 You only need to care about those computers (and thus, about the difference between a char and an octet) if you have one -- let the people who have the weird hardware worry about how to make their programs run on it. 你只需要关心那些计算机(因此,关于char和octet之间的差异),如果你有一个 - 让拥有奇怪硬件的人担心如何在其上运行程序。

An octet string is simply a sequence of bits grouped into chunks of 8. Those 8-sized groups often represent characters. 八位字节字符串只是一组分组为8的块。这些8个大小的组通常代表字符。 Octet string is a basic data type used for SNMP. Octet字符串是用于SNMP的基本数据类型。

A string used to be a set of octets, which is turn is a set of 8 bits. 一个字符串曾经是一组八位字节,它是一个8位的集合。

A string in C, is always a null-terminated, memory contiguous, set of bytes. C中的字符串始终是以空值终止的,内存连续的字节集。 Back in the day, each byte, an octet, represented a character. 在当天,每个字节,一个八位字节,代表一个字符。 That's why they named the type used to make strings, char . 这就是为什么他们将用于制作字符串的类型命名为char

The ASCII table, that goes from 0 to 127, with the graphics/accents version going from 0 to 255, was no longer enough for displaying characters in a string, so someone though of adding bits to a character representation. ASCII表格从0到127,图形/重音版本从0到255,不再足以在字符串中显示字符,所以有人在为字符表示添加位。 Dumb-asses from CS though of 9bit and so forth, to what HW guys replied "are you nuts??? keep it a multiple of memory addressing unit", which was the byte, back then. 来自CS的愚蠢的9比特等等,对于HW家伙的回答“你疯了吗?保持它是内存寻址单元的倍数”,那是当时的字节。 Enter wide-character strings, ie 16bits per character. 输入宽字符串,即每个字符16位。 On a WC string, each character is represented by 2 bytes... there goes your char=1 byte rule down the drain. 在一个WC字符串上,每个字符由2个字节表示...将你的char = 1字节规则放在排水管上。

To keep an exact description of a string, if it's a set of characters-represented-by-8bits (in Earth, following the ASCII table, but I've been to Mars), it's an "octet string". 为了保持字符串的确切描述,如果它是一组由8位表示的字符(在地球上,遵循ASCII表,但我去过火星),它是一个“八位字符串”。

If it's not "octet string" it may or may not be WC... Joel was a nice post on this. 如果它不是“octet string”,它可能是也可能不是WC ... Joel是一个不错的帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM