Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

BYTE increment

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When u incremnt a byte does it get convered to an int;
for eg
byte a;
a++;
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it does:


For more info, check out the spec.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic