char c = 'C', d = 'D'; System.out.println(c $ d) The above code prints 64. How did it derive that number?
Barkat Mardhani
Ranch Hand
Joined: Aug 05, 2002
Posts: 787
posted
0
correction Replace $ with & in above code. Sorry...
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Hi Barkat, Well the int representation for the chars 'c' and 'd' are 67 and 68 respectively. So in binary that would be:
Bitwise anding gives us:
which is 64. Hope this clears it up, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Barkat, Note that you have the ability to edit your posts at JavaRanch. Just click on the icon that looks like a piece of paper with a pencil.
Also - c and d were chars, but c & d is promoted to int by the rules of binary promotion. That's why it prints as the number 64 rather than the char '@' (which has value 64).