This week's book giveaway is in the Design forum.We're giving away four copies of Building Microservices and have Sam Newman on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Building Microservices this week in the Design forum!

# Converting from hex to decimal

Ross Gayle
Greenhorn

Joined: Jan 17, 2004
Posts: 14
I wish to know if there are any simple conversion techniques of integral values from hex (0x7fffffff) to decimal (2147483647) . it can be quite useful in solving questions.

thx....
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
How do you like this?

Ross Gayle
Greenhorn

Joined: Jan 17, 2004
Posts: 14
i meant solving by hand.
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Hexadecimal<-->Binary and Octal<-->Binary is very easy and zero arithematic is needed for that.
As a next step Hexadecimal<-->Octal is also easy if we use binary as a bridge.

All of above works without tedious arithematic.

To do decimal<-->binary a little arithmatic seems to be a must.
If that is not an issue then again binary can be used as a bridge to achieve hexa<-->decimal.

This is what I learnt recently.
[ June 09, 2004: Message edited by: Swamy Nathan ]
maha devan
Ranch Hand

Joined: Mar 16, 2004
Posts: 50
Hi

U can find the hand solving of Different Conversions in books like
Digital Electronics by Moris Mano
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Do they have any nonarithematic based direct solution for hexa<-->decimal in the book?
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
I am copypasting a portion of my notes I built up recetnly based on some material referrred here.
If anyone gives a non-arithematic way for hexadecimal<-->decimal I would also be glad.

[ June 09, 2004: Message edited by: Swamy Nathan ]
Ross Gayle
Greenhorn

Joined: Jan 17, 2004
Posts: 14
thanks a lot for that info Mr. Swamy. It was quite useful. I knew the way to do it , just was checking to see if a better way existed.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Ross,

Welcome to Javaranch

We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.

SCJP Tipline, etc.
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Call me just "Swamy".
I for one didnt know it and learnt this at this forum only.
I too would like to know if there is any way to do the hexa<-->decimal stuff directly.
Maybe someone else like me would find it more useful.

[ June 09, 2004: Message edited by: Swamy Nathan ]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8898

5
Wow Guys !

Very thorough, but luckily the exam is no where near this hard.

The most important thing is to understand two's complement really well, and then understand hex and octal at a high level. You WON'T have to do lots of calculations on the exam, for instance, if you know that -3 in binary has lots of 1111111's you should be in good shape. The other important thing to understand is the shift operators.

If you know two's complement and shifting, go study another section.

- Bert

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187

Its just that alittle insight on how it works helps. Insight is helped from examples (and observing the examples) and viceversa. Dont know about the exam but I found it useful in a few mock test questions. I think I will trust Bert about the exam (fingers crossed) since he wrote a few books and all.

I sometimes overflow with concepts and had a spillover I guess.

Must be the cofee again.
SCJP
[ June 09, 2004: Message edited by: Swamy Nathan ]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8898

5
It's really hard for people who write the mock exams to know EXACTLY what's on the exam - so in general I think mock exams tend to be broader than the real exam. I think that Dan Chisolm amended his mocks after taking the exam to more accurately reflect what's really on the exam.

We also had a thread on this forum a while back - you can search for it - something like 'top ten things you think are on the exam but aren't'

Good luck!

-Bert
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
I just thought I should complete the picture

Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by Bert Bates:
It's really hard for people who write the mock exams to know EXACTLY what's on the exam - so in general I think mock exams tend to be broader than the real exam. I think that Dan Chisholm amended his mocks after taking the exam to more accurately reflect what's really on the exam.

We also had a thread on this forum a while back - you can search for it - something like 'top ten things you think are on the exam but aren't'

Good luck!

-Bert

Yes, that is correct. I developed my mock exam to prepare for the real exam. After passing the real exam, I removed a lot of mock exam questions that were far too difficult or were far beyond the scope of the real exam. What is left are questions that are just a little more difficult than the real exam, and some of the questions might still be just a little beyond the scope of the real exam. Even with this new simplified version of my exam, most people still score higher on the real exam.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Well I have been fretting about my scores in ur mocks. So its comforting to hear that.
Nobuhiro Watsuki
Ranch Hand

Joined: May 07, 2004
Posts: 81
Id do it like this:

123 hex:

(1*16^2) + (2*16^1) + (3*16^0) = the decimal number

SCJP, SCMAD, SCWCD, SCBCD, CCIE (written), IBM 287<a href="http://hollandiahaven.blogspot.com/" target="_blank" rel="nofollow">.</a>
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
I think using "Nobuhiro Watsuki"'s way will cause problems when you try to convert from a byte say FF which is -1 or a short say FFFF again -1. I dont know for sure if there is any other way around.

I agree. Here's the link: http://aspose.com/file-tools

subject: Converting from hex to decimal