Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - curious number declaration

Tags:

java

I have found somewhere a pretty weird number declaration in Java.

double x = 0xap-001;

I am curious why the value of x is 5.0

like image 857
Valy Avatar asked May 05 '15 15:05

Valy


1 Answers

p indicates a binary exponentiation. So you have hex 0xa == 10, with a binary exponent of -1 - in other words a shift right or div 2. The result is 10/2 = 5.

like image 77
BadZen Avatar answered Nov 03 '22 23:11

BadZen