Java converting int to hex and back again

前端 未结 10 1116
鱼传尺愫
鱼传尺愫 2020-11-28 08:34

I have the following code...

int Val=-32768;
String Hex=Integer.toHexString(Val);

This equates to ffff8000

int         


        
10条回答
  •  独厮守ぢ
    2020-11-28 08:46

    It overflows, because the number is negative.

    Try this and it will work:

    int n = (int) Long.parseLong("ffff8000", 16);
    

提交回复
热议问题