corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Subtracting Hexadecial


New Topic

New Poll
  <<  1    2  >> Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Subtracting Hexadecial
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 16:56   View User's Profile U2U Member Reply With Quote

Right, struggling with subtracting two hexadecimal numbers.

I had to convert 678 and 345 (decimal) to hexadecimal, giving me the values of;

678=2A6
345=159

Anyone have any idea how to subtract the two values from one another, and can show me the working out?
John
Member

Registered: 30th Jun 03
User status: Offline
20th Nov 09 at 17:05   View User's Profile U2U Member Reply With Quote

Do they not teach google on your course?
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 17:15   View User's Profile U2U Member Reply With Quote

GOOD ONE, your original.
I've had a look on google but none of them explain it in a way that I understand very well. I figured if someone could show me the actual working out I'd understand it better.
John
Member

Registered: 30th Jun 03
User status: Offline
20th Nov 09 at 17:21   View User's Profile U2U Member Reply With Quote

http://mathforum.org/library/drmath/view/55943.html

Most of the ones I can see explain it very similar to that, it's not much different from working with decimal.
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 17:21   View User's Profile U2U Member Reply With Quote

We start with:

2A6-
159

You need to rationalise the numbers so you can cope with them in your base10 mind:

200 hex - 100 hex is 100 hex.

So you are left with A6 - 59

A0 - 50 = 50
6 - 9 = -3

So you've got (100 + 50) -3

Which with Base10 instincts you would say its 147 but you would be wrong! If you take away 3 from 50 you are going back into another base 16 number so you have 4D so the result is:

14D.
A2H GO
Member

Registered: 14th Sep 04
Location: Stoke
User status: Offline
20th Nov 09 at 17:54   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by DaveyLC
We start with:

2A6-
159

You need to rationalise the numbers so you can cope with them in your base10 mind:

200 hex - 100 hex is 100 hex.

So you are left with A6 - 59

A0 - 50 = 50
6 - 9 = -3

So you've got (100 + 50) -3

Which with Base10 instincts you would say its 147 but you would be wrong! If you take away 3 from 50 you are going back into another base 16 number so you have 4D so the result is:

14D.


Nath
Member

Registered: 3rd Apr 02
Location: MK
User status: Offline
20th Nov 09 at 17:56   View User's Profile U2U Member Reply With Quote

I dont understand anything in this thread tbh.
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 18:04   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by DaveyLC
We start with:

2A6-
159

You need to rationalise the numbers so you can cope with them in your base10 mind:

200 hex - 100 hex is 100 hex.

So you are left with A6 - 59

A0 - 50 = 50
6 - 9 = -3

So you've got (100 + 50) -3

Which with Base10 instincts you would say its 147 but you would be wrong! If you take away 3 from 50 you are going back into another base 16 number so you have 4D so the result is:

14D.


Brilliant! Much easier to follow, cheers .
John
Member

Registered: 30th Jun 03
User status: Offline
20th Nov 09 at 18:18   View User's Profile U2U Member Reply With Quote

You might as well just change it to decimal, do the sum, then change it back if doing it that way.
Cosmo
Member

Registered: 29th Mar 01
Location: Im the real one!
User status: Offline
20th Nov 09 at 18:40   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by John
You might as well just change it to decimal, do the sum, then change it back if doing it that way.


I was going to say the same, if you're going to use the method of changing them then you may as well do so to a much simpler form and then covert it back.
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 18:56   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by ashleh

Brilliant! Much easier to follow, cheers .


No probs I'm a programmer so its something im used to
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 19:15   View User's Profile U2U Member Reply With Quote

I have a phase test on binary, hexadecimal etc as well as logic gates and stuff on Monday so I'm just trying to cram as much as possible over the weekend lmao.
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 19:26   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Cosmo
quote:
Originally posted by John
You might as well just change it to decimal, do the sum, then change it back if doing it that way.


I was going to say the same, if you're going to use the method of changing them then you may as well do so to a much simpler form and then covert it back.


I had originally done this, but I'd rather learn to both the harder way and the simpler way .
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 20:19   View User's Profile U2U Member Reply With Quote

If you are going to do Hex conversions always go back to Base10 then come forward to Base16..

For example:

12D

Again we have to break it down into 100, 10's and remainders (metaphorically speaking).

So we have 100 and 20 and D

100 decimal is 10 x 10 (its a base10 numeric) so 100 hex is 16 x 16 thus:

100 hex = (16 x 16) = 256 dec.

20 hex = (16 x 2) = 32 dec.

Units are simple:

code:

0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF 0x10
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016



D = 13 dec

So 12D = 256 + 32 + 13 = 301 dec

Simples

Getting your head around base16 is an arse because we've spent our whole lives using Base10.


[Edited on 20-11-2009 by DaveyLC]
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 20:23   View User's Profile U2U Member Reply With Quote

Also get into the habit of presenting your Hex numbers like so 0xFF
mwg
Member

Registered: 19th Feb 04
Location: South Lakes
User status: Offline
20th Nov 09 at 20:27   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Nath
I dont understand anything in this thread tbh.


DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 20:28   View User's Profile U2U Member Reply With Quote

Want an idiots guide to Hex? lol
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 20:40   View User's Profile U2U Member Reply With Quote

Massive help Just wondered if you could check this for me, I know it's not hex but still confused me a little.

Right, -15 - 13.
So I convert the binary form of 15 (00001111) using two's complement (11110001).

Using two's complement makes the equation become an addition instead of a subtraction?


11110001
00001101+

11111110?


DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 20:48   View User's Profile U2U Member Reply With Quote

What you have there is 241 +13
code:

128 064 032 016 008 004 002 001
1 1 1 1 0 0 0 1 = 1 + 16 + 32 + 64 + 128 = 241

0 0 0 0 1 1 0 1 = 1 + 4 + 8 = 13



241 + 13 = 245

When you talk about bitwise logic (AND, OR, XAND and XOR etc.) it starts getting a bit more complicated.

[Edited on 20-11-2009 by DaveyLC]
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 21:07   View User's Profile U2U Member Reply With Quote

Hmmm lemme try again. I've been given the equation -15 - 13 (to convert to binary and work out obv). Am I correct in thinkin I'd do it like this;

Convert the 13 in binary to a negative number using two's complement, which also makes the subtraction become an addition.

So effectivly I'm making it -15 + (-13).

[Edited on 20-11-2009 by ashleh]
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 21:16   View User's Profile U2U Member Reply With Quote

Technically there is no such thing as 'negative numbers' in binary you have signed and unsigned numbers and basicall you write off half of your storage capacity as 'minus numbers'

You have to add an extra bit represent if the value is signed..

For example

13 = 1101
15 = 1111

You would then add a 5th bit to act as your signed indicator.

Now we have this:

13 = 01101
15 = 01111

The bold bit is the signed indicator (least significant).

So now you want to go minus you have to turn the signed indicator ON

-13 = 11101
-15 = 11111
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 21:20   View User's Profile U2U Member Reply With Quote

Oh and the answer to your equation is -28 which means the four bit storage above isnt big enough to hold it so you would actually use 6bits (5 bits to store the value 28 and 1 extra bit for the signed indicator)..

In the real world you would use a signed byte which would give you -128 to +128.
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 21:26   View User's Profile U2U Member Reply With Quote

lmao never been shown using that method.
Two's complement is a number scheme that's generally used to represent signed integers...basically you take the positive binary version of the number, invert all the bits then add 1.
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
20th Nov 09 at 21:27   View User's Profile U2U Member Reply With Quote

My background is computing and thats where binary comes from so I'd assume my method is correct
ashleh
Member

Registered: 23rd Dec 08
Location: Nottingham
User status: Offline
20th Nov 09 at 21:32   View User's Profile U2U Member Reply With Quote

I'm not doubting you lmao, it's just I've been told using a different method Just had a look on a site and they use the same method as me so I think I'll stick to that aha .

  <<  1    2  >>
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Cams Adam Engine Work, Tuning & Exhausts 0 8182
10th Dec 02 at 14:29
by Adam Petherick
 
Help desperatly needed from c programmers kerzo Geek Day 24 1852
20th Nov 03 at 01:53
by Jason
 
This is equal to 1 Cybermonkey Geek Day 15 357
26th Oct 06 at 17:10
by John
 
differences between 3 and 5 door fightstar General Chat 18 3342
25th Jun 09 at 13:18
by flame-red
 

Corsa Sport » Message Board » Off Day » Geek Day » Subtracting Hexadecial 28 database queries in 0.0159619 seconds