Reply
Contributor
Posts: 55
Registered: ‎09-17-2013
Accepted Solution

Why HexaDecimal String of any VIntWritable has 8f at the start.?

I am checking some concepts in Definitive guide and could not figure out this small logic.

 

When you convert VIntWritable to Byte Array and convert that byte array to string, there is additional '8f' at the start of any avalue.

 

for eg:

 

for normal IntWritable the value of 172 in hexa decimal representation is - 000000ac

for VIntWritable, the HexaDecimal String for 172  is  8fac

for VIntWritable, the HexaDecimal String for -172 is  87ab

 

I am confused. could you please elaborate a bit.?

Highlighted
Posts: 1,836
Kudos: 415
Solutions: 295
Registered: ‎07-31-2013

Re: Why HexaDecimal String of any VIntWritable has 8f at the start.?

The first byte value is used as the sign indicator, if the number requires more than one byte to encode with.

In your specific example with 172 and -172,
1000|1111, or 8f, is used to indicate positive numbers
1000|0111, or 87, is used to indicate negative numbers

It helps also if you look at the sources to answer such questions, i.e. at https://github.com/cloudera/hadoop-common/blob/cdh5.4.0-release/hadoop-common-project/hadoop-common/... (serialise) and https://github.com/cloudera/hadoop-common/blob/cdh5.4.0-release/hadoop-common-project/hadoop-common/... (deserialise). Also look at this: https://github.com/cloudera/hadoop-common/blob/cdh5.4.0-release/hadoop-common-project/hadoop-common/...

Does this help?
Announcements