• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

binary representation & unicode value of char

 
Shafkat Talli
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question #1: we use two's compliment. Reverse all the digits and add 1:
0000 1100

1111 0011 <-- reverse digits
0000 0001 <-- add 1
---------
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alex Radomski
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
This link might help: unicode webpage

[ August 12, 2003: Message edited by: Alex Radomski ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic