Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become an Expert!

Join 416,725 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,907 people online right now.Registration is fast and FREE... Join Now!



Hexadecimal addition

#1 ~*HOOR*~  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-May 09


Dream Kudos: 0

Share |

Hexadecimal addition

Post icon  Posted 07 May 2009 - 11:03 PM

Hello
I would want somebody to explain me how to add two hex nos.for eg:I have thse two numbers F190 and 23F1.How do I add 9 and F?
Thanks..:)
Was This Post Helpful? 0
  • +
  • -


#2 userlouis  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-November 07


Dream Kudos: 0

Re: Hexadecimal addition

Posted 08 May 2009 - 12:11 AM

View Post~*HOOR*~, on 7 May, 2009 - 11:03 PM, said:

Hello
I would want somebody to explain me how to add two hex nos.for eg:I have thse two numbers F190 and 23F1.How do I add 9 and F?
Thanks..:)


the easiest way for me to do it is to convert the number to binary then add them

F=1111 1=0001 9=1001 0=0000

2=0010 3=0011 F=1111 1=0001

11 1 111111
1111000110010000
+ 0010001111110001
__________________________
10001010110000001 =11581
Was This Post Helpful? 0
  • +
  • -

#3 ~*HOOR*~  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-May 09


Dream Kudos: 0

Re: Hexadecimal addition

Posted 08 May 2009 - 12:25 AM

^^ Thanks.Thats easy for me too but still I would wanna know as to how we can add them directly :)
Thanks
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • Icon

Reputation: 1293
  • View blog
  • Posts: 6,121
  • Joined: 16-October 07


Dream Kudos: 600

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Re: Hexadecimal addition

Posted 08 May 2009 - 01:09 AM

Think about it. In base ten, how do you add 9 and 3? When you give 1 to 9, it shifts over to the next postion up and you're left with two.

Base 16, same deal.
e.g. 9 + F = 8 + 10 = 18

  F190
  23F1
  ----
	 1
	8  
   5   +1
  1	+1
 1
-------
 11581


Was This Post Helpful? 0
  • +
  • -

#5 ~*HOOR*~  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-May 09


Dream Kudos: 0

Re: Hexadecimal addition

Posted 08 May 2009 - 02:00 AM

I still didn't get it.How come 9+F=8+10?
sorry but I am a dumbhead^^
Was This Post Helpful? 0
  • +
  • -

#6 schnalf  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 4
  • View blog
  • Posts: 129
  • Joined: 09-February 08


Dream Kudos: 0

Re: Hexadecimal addition

Posted 08 May 2009 - 02:09 AM

View Post~*HOOR*~, on 8 May, 2009 - 02:00 AM, said:

I still didn't get it.How come 9+F=8+10?
sorry but I am a dumbhead^^


10 is not a decimal 10, it is a hexadecimal 10.
F (decimal 15) + 9 (decimal 9) = 18 (decimal 24)
because:
F (decimal 15) + 1 (first part of the 9) = 10 (decimal 16)
10 (decimal 16) + 8 (rest of the 9) = 18 (decimal 24)

i hope it helps you to understand
Was This Post Helpful? 0
  • +
  • -

#7 ~*HOOR*~  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-May 09


Dream Kudos: 0

Re: Hexadecimal addition

Posted 08 May 2009 - 02:26 AM

I think I got it..Thanks a lot .
Was This Post Helpful? 0
  • +
  • -

#8 baavgai  Icon User is offline

  • Dreaming Coder
  • Icon

Reputation: 1293
  • View blog
  • Posts: 6,121
  • Joined: 16-October 07


Dream Kudos: 600

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Re: Hexadecimal addition

Posted 08 May 2009 - 02:29 AM

View Post~*HOOR*~, on 8 May, 2009 - 04:00 AM, said:

I still didn't get it.How come 9+F=8+10?


You're counting. 0,1,2,3,4,5,6,7,8,9 and you've run out of symbols. You need to represent one more that the last sybol, so you move up a place, in this case 10. What 10 says in base10 that I have (1x10) + (0x1). So base10 256 is read as (2x100) + (5x10) + (6x1). The position of digits represents a power of the base, so 256 = (2x10^2) + (5x10^1) + (6x10^0). We don't ususally think of it like that, but thats what the system means.

So, you're counting. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F and you've run out of symbols... In the above I cheated, because I ultimately had to express things in a base10 system. Techinally, I should say that 256 in a base16 system is (2xF^2) + (5xF^1) + (6xF^0).

So, after F, we continue 10,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20, 21. and so on.

9 + F = 1 + 8 + F, right? And the next number after F is 10. Forget addition and subtraction. Just think about counting. You'll get it.
Was This Post Helpful? 1

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • Icon

Reputation: 1037
  • View blog
  • Posts: 7,737
  • Joined: 18-February 07


Dream Kudos: 1250

Expert In: Java/C++

Re: Hexadecimal addition

Posted 10 May 2009 - 01:38 AM

The only difference between decimal arithmetic and hexadecimal arithmetic is the value of the base.

So think about what happens when you add 8 + 5, start counting up from 8, 5 places, 8 9 -- well we ran out of digits so start a new column and we get 10, 11, 12, 13... therefore 8 + 5 = 13

so in hex: 9h + Fh is, 9h, Ah, Bh, Ch, Dh, Eh, Fh... here we have to move over to the 16's place, 10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h, 18h.


So in decimal we tend to complete 10's -- 8 + 5 == (8 + 2) + (5 -2) = 10 + 3.

9h + Fh = (9h + 7h) + (Fh - 7h) = 10h + 8h = 18h


Remember in hex 10h is 16 decimal. 20h is 2*16=32 decimal.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users