## halkazi 3 years ago In chap 12, we are asked to "As an exercise, create and print a Point object, and then use id to print the object's unique identifier. Translate the hexadecimal form into decimal and confirm that they match." I got an identifier " 0x02B41468". What does x represent in Hex? If I am able to convert this to Decimal, with what do I have to match it?

1. rsmith6559

0x is the traditional C way of denoting that the following number is hexadecimal. 0 by itself denotes octal.

2. andrew.m.higgs

Yes, as Rsmith6559 says, everything after the 0x is the actual hex value. In this case, 02B41468.

3. halkazi

Thanks. Ok, so I converted it to Decimal 45,356,136. With what should I match this. Is there a function that will return the Id in Decimal?

4. rsmith6559

If you have the code that produced the identifier, there's a formatted print command in there to print it out. If we're talking a C based language, it could well be printf(). Usually in the format string, %x or %X is used for hex and %d is used for decimal. Your best bet would be to duplicate the line and have one with an x and one with the d.

5. halkazi

I guess the exercise is not making sense to me. What do I get by converting an object identifier from Hex to Decimal, and verifying it using a formatting command.

6. rsmith6559

Converting it is a valid exercise, but without the answer you can't be sure that you're right. One way to cheat (it's ethical if it's only to check to see if what you got is right or wrong) is to hack the formatted print statement and let the computer give you the answer.

7. exchaoordo

I have the same question as halkazi: I understand hex and I can convert the id to decimal, but the question says "see if they match." See if WHAT matches?

8. exchaoordo

#halkazi, did you ever get a real answer to this? I came up with: 49595656, with what is one supposed to match it? I don't get the thing about hacking formatted print statements etc.

9. rsmith6559

Most languages use something like C's printf statement's formatting strings. This means that when you print a hexadecimal integer, you format it with "%x". If you want to print it as decimal, the format would be "%d". If you have the code, find the line that prints out the hex. Make an exact duplicate of that line on the next line, and change the "%x" to "%d" and recompile and run it.