java - change the bits order -
i have function converts int hex. in function, seekbar's value between 0 , 100. changes , convert hex.
private string decimaltohex(int i) { /**conversion decimal of seekbar's % value*/ int_value = ((i * 20480) / 100) * -1; int_value = -20480 - int_value; /**conversion hex*/ hex_value = integer.tostring(int_value, 16); //hex_value = integer.tohexstring(c2_final); return hex_value; }
lets suppose int i
value 52. gets next value: int_value = -9831
when convert value hex, -2667
. not value need.
i need make conversion gives me hex result value "d999". value ones-complementing value (aka ~
operator). converting value -9831
positve 9831
, substracting 1 9830
, , last, changing bits value 55705
in hex d999
.
how can last thing? change bits?
code in c:
if (int_value < 0) { c2_value = int_value * -1; c2_value = c2_value - 1; c2_final = ~c2_value; }
java.lang.integer
provides tohexstring() method converts specified integer hexadecimal string representation.
you can use following.
log.d(tag, java.lang.integer.tohexstring(-9831));
this give output
08-07 18:53:57.643: d/home(31698): ffffd999
to output, use following code.
string strhex = java.lang.integer.tohexstring(-9831); if (strhex.length() > 4) log.d(tag, strhex.substring(4)); else log.d(tag, strhex);
Comments
Post a Comment