Skip to main content
gamedev.net
🔒 Locked

multi-byte integer question

Started by _nomad_ Oct 25, 2005 at 1:22 AM 1 replies 2k views
Original Post
_nomad_
_nomad_
Hi, According to http://www.w3.org/TR/wbxml/ :
Quote:
Multi-byte Integers This encoding uses a multi-byte representation for integer values. A multi-byte integer consists of a series of octets, where the most significant bit is the continuation flag and the remaining seven bits are a scalar value. The continuation flag indicates that an octet is not the end of the multi-byte sequence. A single integer value is encoded into a sequence of N octets. The first N-1 octets have the continuation flag set to a value of one (1). The final octet in the series has a continuation flag value of zero (0). The remaining seven bits in each octet are encoded in a big-endian order, eg, most significant bit first. The octets are arranged in a big-endian order, eg, the most significant seven bits are transmitted first. In the situation where the initial octet has less than seven bits of value, all unused bits must be set to zero (0). For example, the integer value 0xA0 would be encoded with the two-byte sequence 0x81 0x20. The integer value 0x60 would be encoded with the one-byte sequence 0x60.
how was 0xA0 split up to 0x81 and 0x20? can it also be split up to 0x71 and 0x31? how to know when to split up (0xA0's value is less than a char also, but they split it up to two bytes). thanks! [Edited by - _nomad_ on October 25, 2005 1:43:10 AM]
JohnBolton
JohnBolton
The highest bit of a byte is a flag. That leaves 7 bits available for each byte. The value 0xA0 requires 8 bits, so that means it needs to be split across 2 bytes (since there are only 7 bits available in each byte. 0xA0 is
    10100000 
You split the 8 bits of 0xA0 like this:
    x0000001 x0100000 
(where x is the continuation bit) The first byte has the continuation bit set to 1, the second byte's continuation bit is 0.
    10000001 00100000 
Converting to hex:
    1000 0001  0010 0000      8    1     2    0       0x81       0x20 
0x60 only requires 7 bits so it will all fit in one byte and it is not split
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
_nomad_
_nomad_
i see. i get it now...thanks! :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.