Using up to four characters, write the Java representation of integer literal 10 in hexadecimal. ans: Any of the following are correct answers - 0x0a, 0X0a, 0Xa, 0xa, 0x0A, 0X0A, 0XA, 0xA can anyone explain how to write 10 in hexadecimal format?
Hexidecimal is Base-16. Normal decimal is Base-10. This means we have 10 unique symbols for each decimal "place" we count. They are the familiar 0,1,2,3,4,5,6,7,8,9. In base-10, we can count up to and including 9 "things" in each place. when we count up to 9, we can't go any "higher" in that place, so using rules of base-10 addition, we add one more unit to the place just to the left, and reset the current place to zero. This is how we go from 9 to 10 in decimal math. (Thank the arabs for this revolution!! This is easier than going from IX to X) Hexidecimal has 16 unique symbols for each place, meaning you can count up to 15 things for each position. Since we only have 10 symbols for our base-10 math, we have to come up with some extra symbols for those extra 5 units, so we borrow from our alphabet. Let's count to 15 using hexicecimal. 1 2 3 4 5 6 7 8 9 so far so good, just like regular decimal. Now, unlike decimal, we're not done counting in this column yet. Adding 1 to 9 in hexidecimal gives us A //=10 in decimal then we count B // = 11 in decimal C // = 12 in decimal D // = 13 in decimal E // = 14 in decimal F // = 15 in decimal Now we are out of symbols, so we add one to the next column and reset this one to zero 10 This 10 in hexidecimal is the same as writing 16 in decimal, because we counted 16 unique "things" to write it. I hope this shows you how to write decimal 10 in hexidecimal now!
Rob [ January 19, 2002: Message edited by: Rob Ross ]
you already know how to write 10 in hex you gave the 10 possible answers. as to why: hex numbers are easier to understand by converting them to binary numbers (at least to me). all hex numbers begin with the 0x thing in front of them just to tell us the the following number will be hex and not octal or binary etc... then you can write up to four numbers or characters between 0 and F . for me , to make thing easier i convert each number or character to a binary representaion like this: if you got 0x1234 then it looks like this in binary: 0001 0010 0011 0100 ( 1 2 3 4 in binary) now just sum it up in binary form which is easier, like: 2^12+2^9+2^5+2^4+2^2=4660 phew! so 0*1234 in hex is 4660. now i mentioned that u can use also charcters a b c d e f which mean in binary: 10 11 12 13 14 15 . so now lets take 0*a and see what we get: a is 10 in binary (and also decimal so its quite easy). if we write it in binary you get: 1010 which is : 2^3+2^1 = 10 thats it capital lettesr dont matter.