Octet String: What is it?

Viewed 109061

I am starting to look into some network programming concepts for a project I am about to take over, and I keep running into this concept of an octet string. Can anyone out there provide some feedback into what this is, and how it relates to network programming?

9 Answers

Octet = byte.

Octet string = sequence of bytes.

Also, see Wikipedia.

"Octet" is standardese for "8-bit byte". It's supposed to be a less ambiguous term compared to just "byte", because some platforms have bytes of different width (not sure if there are any are still remaining, but they used to exist).

A group of 8 bits in a computer is called an octet. A byte is the same for most practical purposes, but does not equal 8 bits on all computer architectures. More can be found here .. Link

The term "octet" is used to avoid ambiguity, because some old computers had different numbers of bits per byte.

Unlike what the name suggests, this data type is not limited to string values but can store any byte based data type (including binary data).

Below is a Java based class that tries to convert a Decimal to its OctetString.

public class deboctetstring {

private String findOctet (int num) {

    int rem;
    String output ="";
    char ind[] = {0,1,2,3,4,5,6,7};
    while (num > 0) {
     
        rem = num%8;
        output = ind[rem] + output;
        num = num/8;

    }  
    
    return output;
}

public static void main(String[] args) {
    System.out.println("Start octet test");
    deboctetstring deboct = new deboctetstring();
    int x = 72;
    String octetval = deboct.findOctet(x);

    System.out.println("Octet Value of Decimal "+ x + " is: "+ octetval );
}

}

Here is a python3 Code for the conversion of decimal to OctetString: Very easy

Number = 2680
Bin = format(Number, 'b')
Sp = [hex(int(Bin[::-1][i:i+7][::-1],2)) for i in range(0, len(Bin), 7)]
print(Sp)
Related