This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# binary representation & unicode value of char

Shafkat Talli
Ranch Hand
Posts: 30
I have 2 questions:
--------------------
Question 1:
-----------
i am trying to figure out how i get negative binary representation:
I have no problems with the positive numbers, but i dont understand how one gets negative numbers.
For example:
1100 0000 = 12
But what is = -12 , and how do one make a binary representation of it.

Question 2
----------
One can get question on the exam where one needs to verify of valid declarations of char:
f.ex.
char a = '\u004E'
char b = '\ubeef'
char c = '\umonkey'
2 of these are right, and one wrong. But my question really is how i know if one unicode value is valid or not ? is there any reference to it on the net ?

All help appreciated.

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
Question #1: we use two's compliment. Reverse all the digits and add 1:
0000 1100

1111 0011 <-- reverse digits
---------
1111 0100 < -12
Question #2: Unicode is in hex so any 4 digit hex number is valid (there are a few exceptions to this because some of the unicode values are things like "new line" that cause the value to evaluate in your code into a new line which causes a syntax error).
[ August 12, 2003: Message edited by: Thomas Paul ]

Veena Pointi
Ranch Hand
Posts: 442
For first question I think following discussion will be helpfull.
http://www.coderanch.com/t/238653/java-programmer-SCJP/certification/Converting-negative-numbers-binary
Veena