• Post Reply Bookmark Topic Watch Topic
  • New Topic

casting  RSS feed

 
cybel sheriden
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

byte a=10;
byte b=20;
byte d=(byte)(a^b);

i guess in the above statement casting is requried.
so is it like any arthmetic or boolean operation performed on int or smaller than int requries a cast.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct. All arithmetic operations result in at least an int, so when performing an operation on two bytes, the result is still an int and you need to perform a cast to get it back into another byte.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!