• 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

'k' | 35 (i.e char value | int value)

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!!
I just wanted to know if such questions can be part of some code in the exam?I haven't encountered any so far in the books but was just curious when I was trying out my own practice code.But if it occurs in the exam,how do we represent a char value in binary form to do the (|)or any bitwise operations.The result of the following expn is 107.
char x='k';
int y=35;
int z=x|y;
System.out.println("x|y val="+z);
If there is a probability for such a question in the exam please help me regarding this,otherwise don't waste your time.Thanks.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
I didn't come across any question like this in my exam. They don't expect you to remember the whole bunch of values.
HTH
 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The example above performs the following
107|35 (Here 107 is the ascii of character 'k')
Even though you dont need to know the ascii values , I think you should
know that in any arithmetic expression involving byte/short/char, they are always widened to an int.
For example:
byte b = 10;
short s = 12;
char c = 'r';
b + s + c = ?
int i = b + s + c;
Another example:
byte b = 3, c = 4;
byte d = b + c; //error since b + c will be widened to an int
So the above error can be fixed in 2 ways
1. byte d = (byte) (b + c);
2. int d = b + c;
I hope this helps.
[ November 21, 2003: Message edited by: Cathy Song ]
 
Sagarika nair
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kalai for letting me know that such a question doesn't occur in the exam and thanks Cathy for your explanation eventhough I know about the automatic promotion rules.What I didn't understand is the significance of the promotion rules in my question about char representation.Thanks anyways.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think JLS is better catch to know about the most of the automatic conversions friend.
regs
Vivek Nidhi
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic