Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Rising Star

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.?

1 ACCEPTED SOLUTION

avatar
Mentor
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?

View solution in original post

1 REPLY 1

avatar
Mentor
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?