Increase Hex (JAVA)

can you increase the hex value in java? that is, "hexadecimal value" = "hexadecimal value" ++

+5
source share
5 answers

It depends on how the hex value is stored. If you have a hexadecimal value in a string, convert it to Integer, increase and convert it.

int value = Integer.parseInt(hex, 16);
value++;
String incHex = Integer.toHexString(value);
+11
source

What does "hexadecimal value" mean? What type of data is your value stored in?

Note that int / short / char / ... doesn't care how your value was originally represented:

int i1 = 0x10;
int i2 = 16;

i1 i2 . Java ( ) /.

+10

: .

myHexValue++;

. , " " . ( )

Integer.toHexString( myHexValue )

Integer.parseInt( someHexString, 16 );

.

+9

. ints , , .

int hex = 0xff;
hex++;  // hex is now 0x100, or 256
int hex2 = 255;
hex2++; // hex2 is now 256, or 0x100
+3

- . . , . , , " ?".

0

All Articles