Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subtract or add two hexadecimal value in java

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

String sHex = "f7c0";
String bHex = "040000000";
like image 980
michdraft Avatar asked Jan 18 '23 05:01

michdraft


1 Answers

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);

like image 88
ziesemer Avatar answered Feb 01 '23 03:02

ziesemer