How to subtract or add two hexadecimal value in java

michdraft picture michdraft · Nov 23, 2011 · Viewed 19.9k times · Source

Is there a way of calculating two hexadecimal value without converting it to int? for example:

String sHex = "f7c0";
String bHex = "040000000";

Answer

ziesemer picture ziesemer · Nov 23, 2011

Hexadecimal values are integers - just represented in hex instead of decimal.

Can't you just do this?

int sHex = 0xf7c0;
int bHex = 0x040000000;

If not, then you actually meant:

String sHex = "f7c0";
String bHex = "040000000";

In which case, the fastest way to do this is still by converting them to integers, using something like Integer.parseInt(sHex, 16);