Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

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?

like image 265
Kiran Avatar asked Jul 08 '10 19:07

Kiran


3 Answers

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.

like image 160
Jerry Coffin Avatar answered Oct 24 '22 03:10

Jerry Coffin


  • An octet is another word for a 8-bit byte.
  • A char is usually 8 bits, but may be another size on some architectures.
like image 29
Sjoerd Avatar answered Oct 24 '22 04:10

Sjoerd


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.

like image 1
cHao Avatar answered Oct 24 '22 04:10

cHao