b is converted to long type.Over thereHexadecimal0xcafebabe -> 32 bit int, because the left operand is of type logn, so it is extended and converted to sign.Incorrect operation value is displayed.Yeah, this is good.The problem is that if you take a decimal number,System.out.println (Integer.toHexString (-889275714)); // cafebabeSystem.out.println (Long.toHexString (3405691582L)); // cafebabe -> extendedSystem.out.println (Integer.parseUnsignedInt ("cafebabe", 16)); //..." />

I am getting an error when converting Java hexadecimal to decimal

System.out.println ("Hex fun: + Long.toHexString (0x100000000L + 0xcafebabe));

I have the code above,

In Java, if the operand data type is different,

Do not do widening conversion.

long a = 10;

int b = 2;

a + b -> b is converted to long type.

Over there

Hexadecimal

0xcafebabe -> 32 bit int, because the left operand is of type logn, so it is extended and converted to sign.

Incorrect operation value is displayed.

Yeah, this is good.

The problem is that if you take a decimal number,

System.out.println (Integer.toHexString (-889275714)); // cafebabe

System.out.println (Long.toHexString (3405691582L)); // cafebabe -> extended

System.out.println (Integer.parseUnsignedInt ("cafebabe", 16)); //...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts