Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BYTE increment

 
Nikhilesh Fonseca
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When u incremnt a byte does it get convered to an int;
for eg
byte a;
a++;
 
Daniel Moore
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does:


For more info, check out the spec.
 
Jason Fox
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure there's no implicit casting going on here. If you continue the loop, you'll see that value of b never exceeds the value of a signed byte, merely that the sign changes. So unless I misunderstand what's going on (some one please correct me if I am), I believe that no, there is no casting going on and that doing an increment (or decrement) operation on a byte does not implicitly change the byte to an int.

Also, I read the spec Daniel Moore posted, and I was unable to find where it mentions implicit casting in the increment operator. Could someone please point me in the right direction?
[ August 24, 2004: Message edited by: Jason Fox ]
 
shilpa challa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe incrementing byte (byte b with increment operator (b++
does not convert it to int but by explicitly adding 1 to byte will convert it to int (b = b+1 .
 
Nikhilesh Fonseca
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx guys!!
Jason Fox ,shilpa challa ,Daniel Moore
I tried something like the code which Daniel wrote .Silly of me not to try it out earlier.at 127 of the increment operation it gets rounded to-128 and again at -1 to 0.So i guess it still remains a Byte.
So thanx u all
Nikhilesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic