-
Notifications
You must be signed in to change notification settings - Fork 0
Octets
tpkarras edited this page May 13, 2025
·
7 revisions
Octets are numbers containing a binary sequence that indicates either the number or a continuation of said sequence.
Each octet is an 8 bit string, bits 1-8 can be either 1 or 0, bit 8 indicates whether it's a continuation (1) or a terminus (0).
Octets must be 0-128 or 255, examples are provided below.
- The number 0.
00000000 - The number 127.
11111110 - The number 128.
10000000 - The number 255.
11111111
You will have to create a function to parse numbers into a series of octets. As mentioned before, octets must have a length number containing the number of octets preceding the content of octets.
An example function is provided below.
$data = "";
$current_position = 0;
while(true){
$number = hexdec(bin2hex(substr($data, $current_position, 1)));
$current_position++;
if($number === 255){
$element = $element + ($number >> 1) + 1;
} else if($number <= 128){
$element = $element + $number;
} else if ($number > 128){
//return exception;
}
}It is ultimately up to you on how to implement the octet creating/parsing function.