Solved

Converting from hexadecimal using two's compliment

Posted on 2014-04-19
2
273 Views
Last Modified: 2014-04-20
What are the steps you would take to convert a hexadecimal number such as 0x0AB00000 to a decimal number, knowing that it is an unsigned integer. Are there different steps to convert this number if you knew that it was two's compliment instead of an unsigned integer?
0
Comment
Question by:pcomb
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40010525
Yes,

The first step is the same either way as you need to convert the hex number to binary

In your example it is

00001010 10110000 00000000 00000000

This converts to a positive decimal value of 179306496

For a two's compliment, the most significant bit defines the sign, in this case, its 0 so its a positive number.

If we ignored your leading 0 in the hex string, and it was AB00000 then the first 4 0's are now not present and the most significant bit is now a 1 indicating a negative number.

The decimal value of the remaining bits is 45088768, and to get the negative value we subtract this value from 2^N where N is the number of bits in the original number (28)

2^28 = 268435456

so number = 268435456 - 45088768 = -223346688

Using a simpler example

10000000 = 2^8 - 0 = -128
11111111 = 2^8 - 127 = -1
0
 
LVL 26

Expert Comment

by:skullnobrains
ID: 40011081
$ echo 'ibase=16 ; ob=10 ; 0AB00000' | bc
179306496
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you will get to know about pros and cons of storage drives HDD, SSD and SSHD.
Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question