6

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

1

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.