This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 'k' | 35 (i.e char value | int value) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " Watch " New topic
Author

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

Sagarika nair
Ranch Hand

Joined: Aug 13, 2003
Posts: 39
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.
Kalai Ganesh
Ranch Hand

Joined: Sep 08, 2003
Posts: 32
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
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
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

Joined: Aug 13, 2003
Posts: 39
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.
Vivek Nidhi
Ranch Hand

Joined: Aug 10, 2003
Posts: 133
I think JLS is better catch to know about the most of the automatic conversions friend.
regs
Vivek Nidhi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'k' | 35 (i.e char value | int value)
 
Similar Threads
Finding the index of a character in an array
how to compare the values in arrays
Operators Precedence
Q's On My Exam Prep
explain this ...please