Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regading Byte.MAX_VALUE

 
Chandra Sekhar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is the result of the following expression ?
(byte) (Byte.MAX_VALUE + 1) == Byte.MIN_VALUE
This will print true.
Can some one help me to find the reason why it prints true.
Regards
Chandrasekhar S
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byte.MAX_VALUE is 127 , that is 0x7f
Byte.MIN_VALUE is -128 , that is 0x80
0x7f + 1 = 0x80

A simple knowledge about binary, hexadecimal and two's complement is necessary for the exam. Read about them in the web or maybe just search in the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic