Comparing signed hex numbers

Viewed 1026

I have to use ints in java card but since the card itself does not support integers I use byte[] instead.

To represent numbers in hexadecimal format I check the first bit, if it is 1 - negative, if it is 0 - positive (binary wise). So if the leading bit is smaller than 8 it is positive, otherwise negative (hex wise).

Highest number: 7FFFFFFF

Lowest number: 80000000

Now I am wondering if I want to compare a value eg. 00000001 if it is to high/low, do I check without the most significant bit (FFFFFFF > 0000001 > 0000000) and check the most significant bit seperately (if > 7 => negative, else => positive) or is there a "smoother" way to do it?

1 Answers
Related