简体   繁体   中英

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

What is the difference between octet string and char? How can an octet string be used? Can anybody write a small C program on Octet string? How are octet strings stored in memory?

Standards (and such) use "octet" to explicitly state that they're talking about 8-bit groups. While most current computers work with bytes that are also 8 bits in size, that's not necessarily the case. 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.
  • A char is usually 8 bits, but may be another size on some architectures.

An octet is 8 bits meant to be handled together (hence the "oct" in "octet"). 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. But there have been computers with 9-bit, 16-bit, even 36-bit "words" that qualify as chars by that definition. 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.

An octet string is simply a sequence of bits grouped into chunks of 8. Those 8-sized groups often represent characters. Octet string is a basic data type used for SNMP.

A string used to be a set of octets, which is turn is a set of 8 bits.

A string in C, is always a null-terminated, memory contiguous, set of bytes. Back in the day, each byte, an octet, represented a character. That's why they named the type used to make strings, 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. 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. Enter wide-character strings, ie 16bits per character. On a WC string, each character is represented by 2 bytes... there goes your char=1 byte rule down the drain.

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".

If it's not "octet string" it may or may not be WC... Joel was a nice post on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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