Java - curious number announcement

I found a rather strange number declaration in Java somewhere.

double x = 0xap-001; 

I'm curious why the x value is 5.0

+6
source share
1 answer

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

+8
source

Source: https://habr.com/ru/post/986581/


All Articles