This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Why leave out the octal notation? Even if a few people use it, you still need it in the language. And when Java came out ten years ago there were probably more people who used octal than there are nowadays. You can't remove support for their legacy programming just because octal is hardly used any more.
Anyway there are at least two easy ways to convert binary. 1: Use a sort of lookup table,
. . .
. . .
2: Use a parser, eg
Joined: Oct 13, 2005
And you know you can use bit manipulation. You can use an int, eg 00000000000011011101111111100001 and "and" it with another int, eg 10000000000000000000000000000000 That present example will give 0 for all positive numbers, and Integer.MIN_VALUE for any negative numbers, because you will only get the most significant bit (farthest left) coming through if it is "1" in both numbers. In code that would come out as
If you use & 4, you will get 4 if your number has a "1" in its no 2 bit (ie 3rd from the right) (which is equivalent to myFirstInt % 4 > 3), and 0 if that bit it "0" (or myfirstInt % 4 <= 3). That is how those numbers work where you use 1 2 4 8 etc. Go to the API specification, look up the Font class, find the fields BOLD or ITALIC, and look up their Constant values. You will find values of 1 2 4 etc. So you can actually add up those values to get something like 3 = bold and italic.