• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binary Numbers Promotion, Please Clarify

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, in my study notes I have the following:
1) System.out.println(4 + '' + 2); prints 38. Binary numbers promotion rule. Java will promote each operand of a binary operator to it's widest type. Java promotes the character literal('') to it's Unicode value 32.
2) 'b'+ 63; compiles correctly, promoting char to int. 98 giving 161. All operands of type byte, char, short are promoted to at least int before mathematical operations are performed. If one of the operands is larger than an int, then the other is promoted to the same type.
My question is why is the char literal in note 1 ('')given an int value of 32(I suppose) and the char in note 2 ('b') promoted to int value 98
Thanks :confused
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike
JAva uses unicode to represent its tokens internally. From the JLS section 3.1 'The first 128 characters of the Unicode character encoding are the ASCII characters.'
For a good reference of the ASCII characters and their values check out this page.
hope that helps
 
Mike Kelly
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AhhHah! Thanks for the links. But Dave, how the heck is a fella supposed to know that? Experience I guess. Geez.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Kelly:
...how the heck is a fella supposed to know that?

Learn C as your first real language
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic