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

while converting int to byte?

 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i am trying to convert int to byte.
300
in binary : 0000 0000 0000 0000 0000 0001 0010 1100
after truncating HO bytes 0010 1100
inverting 1101 0011
adding one 1101 0100

manually doing i am getting this as output. but the complier is showing 44 .may i know why ? am i wrong in any step ?please help

thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you only need to invert/add 1 if the lead/high bit is 1. Since after the truncation the lead bit is 0, you shouldn't.

Then it's simply adding up the powers of 2 to get 44.
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic