Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting from hexadecimal using two's compliment

Posted on 2014-04-19
2
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 2000 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 27

Expert Comment

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

Featured Post

Enhanced Intelligibility Without Cable Clutter

Challenge: The ESA office in Brussels wanted a reliable audio conference system for video conferences. Their requirement - No participant must be left out from the conference and the audio quality must not be compromised.

Question has a verified solution.

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

What do we know about Legacy Video Conferencing? - Full IT support needed! - Complicated systems at outrageous prices! - Intense training required! Highfive believes we need to embrace a new alternative.
Stuck in voice control mode on your Amazon Firestick?  Here is how to turn it off!!!
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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