• Post Reply Bookmark Topic Watch Topic
  • New Topic

byte type  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why do we need to do an explicit cast for 192 and 168 in line 2 above ?

I only know this much: a byte's range is -128 to 127.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So haven't you answered your own question?!
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does it mean that casting 192 to byte would mean that the byte is now storing -64 ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an int, 192 in binary is...

0000 0000 0000 0000 0000 0000 1100 0000

Casting this value to a byte discards everything except the 8 rightmost bits...

1100 0000

...which is -64.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!