Skip to main content
gamedev.net
🔒 Locked

Hexadecimals

Started by simple 19 replies 800+ views
Original Post
simple
simple
hey guys , what is the result in decimal and how do you calculate it 1a + 2c = ? thanks alot..
Fruny
Fruny
In hex, ''tens'' are worth 16 instead of 10, ''hundreds'' are worth 16*16 instead of 100...
And a,b,c,d,e,f are used as extra digits worth 10 to 15.

Now you can work out the solution.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Oluseyi
Oluseyi
It''s not supposed to be 48, it''s supposed to be 70:
1a = 1 * 161 + 10 * 160 = 16 + 10 = 26
2c = 2 * 161 + 12 * 160 = 32 + 12 = 44
26 + 44 = 70.
Black Marq
Black Marq
quote:
Original post by simple
hey guys , what is the result in decimal and how do you calculate it

1a + 2c = ?

thanks alot..


Well it time for a little lesson then. First what I like to do is convert the number into base 10 or decimal which is regular human numbers. Then I do the math operation and converted back to hex or base 16. After a while when you do it enough it becomes just like regular math and it gets easier.
So lets get started shall we.

First lets convert our number into binary it will be easier to convert to decimal from there.
Here's a list of hex converted to binary:
hex = BIN:
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
a = 1010 = 10 in decimal
b = 1011 = 11 in decimal
c = 1100 = 12 in decimal
d = 1101 = 13 in decimal
e - 1110 = 14 in decimal
f - 1111 = 15 in decimal
So
1 = 0001
a = 1010
put them together then you get 00011010
Now we do a little trick to convert it to decimal. First lets make this binary easier to read by changing its orientation from left-right to up-down.
0
0
0
1
1
0
1
0
First we find the first "1" reading top to bottom.
1. Add this number to your total, move to the next number
2. before you add the next number first double your total then add the number, move to the next number
3. Do 2. again and again until there are no remaining numbers

Now apply our algorthim to our binary number
0 - do nothing
0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
1 - double total, total = 2 and add 1. total = 3
0 - double total, total = 6 and add 0. total = 6
1 - double total, total = 12 and add 1. total = 13
0 - double total, total = 26 and add 0. total = 26

Ok now. We know that "1a" has been converted and we know it equal 26 in decimal.

Now we must convert the second number 2c to decimal:
2 = 0010
c = 1100
Now we put in such away that its in a more readable orientation
0
0
1
0
1
1
0
0
Now apply the Algorithm you just learned

0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
0 - double total, total = 2 and add 0. total = 2
1 - double total, total = 4 and add 1. total = 5
1 - double total, total = 10 and add 1. total = 11
0 - double total, total = 22 and add 0. total = 22
0 - double total, total = 44 and add 0. total = 44

So ok now that "2c" has been converted and we know it equal 44 in decimal.

so
1a + 2c = ? - hexidecimal format

22 + 44 = 66 - decimal format

Now to convert 66 back to hex you must do the opposite. Convert 66 into a binary number and then to a hex number.

This is how we Convert a decimal into a binary
66 / 2 = 33 - 1
32 / 2 = 16 - 0
16 / 2 = 08 - 0
08 / 2 = 04 - 0
04 / 2 = 02 - 0
02 / 2 = 01 - 1
00 ----= 00 - 0

Take the decimal number divide by 2. If the result is an odd number then subtract 1 from the result then continue dividing result again. If the number is even then just divide again until you get to zero.

Remember to keep the 1 and 0's separate from the divide numbers.

Converting 66 give us the binary number of 1000010. Now we must convert this binary in even columns of 4
100 0010
You notice that you might not have enough digits. Just a zero to the beginning of the first binary number and you'll be fine. Now the binary number looks like this
0100 0010
0100 = 4
0010 = 2
your hex number = 42h

and that how you calculate in hex. Don't worry this method may seem really long, but eventually you fiquire out some shorts cut that well make the calculation a little quicker.

Hope this has been educational for you.

Later
-BM-










Edited by - Black Marq on November 30, 2001 3:31:55 AM
simple
simple
quote:
Original post by Black Marq
[quote]Original post by simple
hey guys , what is the result in decimal and how do you calculate it

1a + 2c = ?

thanks alot..


Well it time for a little lesson then. First what I like to do is convert the number into base 10 or decimal which is regular human numbers. Then I do the math operation and converted back to hex or base 16. After a while when you do it enough it becomes just like regular math and it gets easier.
So lets get started shall we.

First lets convert our number into binary it will be easier to convert to decimal from there.
Here''s a list of hex converted to binary:
hex = BIN:
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
a = 1010 = 10 in decimal
b = 1011 = 11 in decimal
c = 1100 = 12 in decimal
d = 1101 = 13 in decimal
e - 1110 = 14 in decimal
f - 1111 = 15 in decimal
So
1 = 0001
a = 1010
put them together then you get 00011010
Now we do a little trick to convert it to decimal. First lets make this binary easier to read by changing its orientation from left-right to up-down.
0
0
0
1
1
0
1
0
First we find the first "1" reading top to bottom.
1. Add this number to your total, move to the next number
2. before you add the next number first double your total then add the number, move to the next number
3. Do 2. again and again until there are no remaining numbers

Now apply our algorthim to our binary number
0 - do nothing
0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
1 - double total, total = 2 and add 1. total = 3
0 - double total, total = 6 and add 0. total = 6
1 - double total, total = 12 and add 1. total = 13
0 - double total, total = 26 and add 0. total = 26

Ok now. We know that "1a" has been converted and we know it equal 26 in decimal.

Now we must convert the second number 2c to decimal:
2 = 0010
c = 1100
Now we put in such away that its in a more readable orientation
0
0
1
0
1
1
0
0
Now apply the Algorithm you just learned

0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
0 - double total, total = 2 and add 0. total = 2
1 - double total, total = 4 and add 1. total = 5
1 - double total, total = 10 and add 1. total = 11
0 - double total, total = 22 and add 0. total = 22
0 - double total, total = 44 and add 0. total = 44

So ok now that "2c" has been converted and we know it equal 44 in decimal.

so
1a + 2c = ? - hexidecimal format

22 + 44 = 66 - decimal format

Now to convert 66 back to hex you must do the opposite. Convert 66 into a binary number and then to a hex number.

This is how we Convert a decimal into a binary
66 / 2 = 33 - 1
32 / 2 = 16 - 0
16 / 2 = 08 - 0
08 / 2 = 04 - 0
04 / 2 = 02 - 0
02 / 2 = 01 - 1
00 ----= 00 - 0

Take the decimal number divide by 2. If the result is an odd number then subtract 1 from the result then continue dividing result again. If the number is even then just divide again until you get to zero.

Remember to keep the 1 and 0''s separate from the divide numbers.

Converting 66 give us the binary number of 1000010. Now we must convert this binary in even columns of 4
100 0010
You notice that you might not have enough digits. Just a zero to the beginning of the first binary number and you''ll be fine. Now the binary number looks like this
0100 0010
0100 = 4
0010 = 2
your hex number = 42h

and that how you calculate in hex. Don''t worry this method may seem really long, but eventually you fiquire out some shorts cut that well make the calculation a little quicker.

Hope this has been educational for you.

Later
-BM-










Edited by - Black Marq on November 30, 2001 3:31:55 AM

Thanks a really got it now.. how it works

simple
simple
quote:
Original post by Black Marq
[quote]Original post by simple
hey guys , what is the result in decimal and how do you calculate it

1a + 2c = ?

thanks alot..


Well it time for a little lesson then. First what I like to do is convert the number into base 10 or decimal which is regular human numbers. Then I do the math operation and converted back to hex or base 16. After a while when you do it enough it becomes just like regular math and it gets easier.
So lets get started shall we.

First lets convert our number into binary it will be easier to convert to decimal from there.
Here''s a list of hex converted to binary:
hex = BIN:
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
a = 1010 = 10 in decimal
b = 1011 = 11 in decimal
c = 1100 = 12 in decimal
d = 1101 = 13 in decimal
e - 1110 = 14 in decimal
f - 1111 = 15 in decimal
So
1 = 0001
a = 1010
put them together then you get 00011010
Now we do a little trick to convert it to decimal. First lets make this binary easier to read by changing its orientation from left-right to up-down.
0
0
0
1
1
0
1
0
First we find the first "1" reading top to bottom.
1. Add this number to your total, move to the next number
2. before you add the next number first double your total then add the number, move to the next number
3. Do 2. again and again until there are no remaining numbers

Now apply our algorthim to our binary number
0 - do nothing
0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
1 - double total, total = 2 and add 1. total = 3
0 - double total, total = 6 and add 0. total = 6
1 - double total, total = 12 and add 1. total = 13
0 - double total, total = 26 and add 0. total = 26

Ok now. We know that "1a" has been converted and we know it equal 26 in decimal.

Now we must convert the second number 2c to decimal:
2 = 0010
c = 1100
Now we put in such away that its in a more readable orientation
0
0
1
0
1
1
0
0
Now apply the Algorithm you just learned

0 - do nothing
0 - do nothing
1 - add this number to total, total = 1
0 - double total, total = 2 and add 0. total = 2
1 - double total, total = 4 and add 1. total = 5
1 - double total, total = 10 and add 1. total = 11
0 - double total, total = 22 and add 0. total = 22
0 - double total, total = 44 and add 0. total = 44

So ok now that "2c" has been converted and we know it equal 44 in decimal.

so
1a + 2c = ? - hexidecimal format

22 + 44 = 66 - decimal format

Now to convert 66 back to hex you must do the opposite. Convert 66 into a binary number and then to a hex number.

This is how we Convert a decimal into a binary
66 / 2 = 33 - 1
32 / 2 = 16 - 0
16 / 2 = 08 - 0
08 / 2 = 04 - 0
04 / 2 = 02 - 0
02 / 2 = 01 - 1
00 ----= 00 - 0

Take the decimal number divide by 2. If the result is an odd number then subtract 1 from the result then continue dividing result again. If the number is even then just divide again until you get to zero.

Remember to keep the 1 and 0''s separate from the divide numbers.

Converting 66 give us the binary number of 1000010. Now we must convert this binary in even columns of 4
100 0010
You notice that you might not have enough digits. Just a zero to the beginning of the first binary number and you''ll be fine. Now the binary number looks like this
0100 0010
0100 = 4
0010 = 2
your hex number = 42h

and that how you calculate in hex. Don''t worry this method may seem really long, but eventually you fiquire out some shorts cut that well make the calculation a little quicker.

Hope this has been educational for you.

Later
-BM-










Edited by - Black Marq on November 30, 2001 3:31:55 AM

Thanks i really got it now.. how it works

Black Marq
Black Marq
Sorry I made copying mistake. Trying to fix right now.

quote:

1a + 2c = ? - hexidecimal format

22 + 44 = 66 - decimal format



the number 22 is suppose to be 26

26 + 44 = 70

But continue following the rules I have provide subsituding 70 and you'll be ok.

Edited by - Black Marq on November 30, 2001 3:45:47 AM
simple
simple
quote:
Original post by Black Marq
Sorry I think I made a mistake. Trying to fix right now.


yes i think answer is 70 not 66 is it

Stoffel
Stoffel
Just FYI, because it took me far too long before I realized this...
If you''re running Windows, the calculator application in Programs->Accessories has a menu View->Scientific that transforms your normal dumb calculator into a nifty one, including Hex Dec Oct Bin buttons. I find it incredibly useful for checking bitmasks.
Black Marq
Black Marq
I didn't mine the question. He/she wanted to know how to calculated numbers in hex format. I knew and then I showed him/her.
Whether I was doing his/her homework or not it was only one question not a hundred of them.

So is that bad? And yes there is a scientific calculator in windows, but that defeats the purpose of the excise. Wouldn't you agreed. Ha ha lol I'm right!!

-BM-

Edited by - Black Marq on November 30, 2001 5:00:59 PM
scaught
scaught
Am I the only one then that adds hex like I do decimal? eg:

For 0x1a + 0x2c:
a + c = 22 which is a 0x06 and a carried 1
1 + 2 (+ the carried 1) = 4
answer = 0x46

This way when you add things like 0xbeef and 0xf00d (the most edible hex numbers around) you only have to do one large conversion to find the answer (instead of two)

Black Marq
Black Marq
quote:
Original post by scaught
Am I the only one then that adds hex like I do decimal? eg:

For 0x1a + 0x2c:
a + c = 22 which is a 0x06 and a carried 1
1 + 2 (+ the carried 1) = 4
answer = 0x46

This way when you add things like 0xbeef and 0xf00d (the most edible hex numbers around) you only have to do one large conversion to find the answer (instead of two)




I'm not quite that good yet I still have to convert to binary. But I can add in binary really easy.
0x1a
1 = 0001
a = 1010
----0001 1010
0x2c
2 = 0010
c = 1100
----0010 1100

add the binaries
0x1a
----0001 1010
+0x2c
---+0010 1100
====0100 0110
hex
====4 6 h

Edited by - Black Marq on November 30, 2001 6:03:17 PM
Red Ant
Red Ant
Heh, I''m too dumb for any of that. Usually I convert both operands to decimals add them up/subtract one from the other/whatever, and then convert the result back to a hexadecimal. :p
Spinal Confusion
Spinal Confusion
quote:
Original post by scaught
Am I the only one then that adds hex like I do decimal? eg:

For 0x1a + 0x2c:
a + c = 22 which is a 0x06 and a carried 1
1 + 2 (+ the carried 1) = 4
answer = 0x46

This way when you add things like 0xbeef and 0xf00d (the most edible hex numbers around) you only have to do one large conversion to find the answer (instead of two)




No, you are not the only one. I do it that way, too. :-)

-Steven
Black Marq
Black Marq
TO: scaught and Spinal Confusion
Umm I was curious to know when you guyz say you can add in hex I believe you can add in hex. But what I want to know is that when you look at a hex number like:
A43D C64E

Do you know what it value is in decimal without using a special calculator. In this case of A43D C64E this is = to 2755511886 in decimal.

Just wondering?

-BM-
ATronic
ATronic
Some people on this forum scare me, mostly because I''m not as experienced as them. Among these people are those that do hex multiplication in their head, and know PI to the 60th decimal place. Ack! I should end it now! Hehehe. Anyway, I am just starting to learn hex, and am a bit confused. You see, I understand some basic things, but I don''t see how each number relates to the next. For example, how would one, step by step, get the decimal number for 5A2FF? Oh, and no, this is not hw. This is me learning hex on my spare time, which makes some of my friends think I''m loosing it. (-:.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Red Ant
Red Ant
quote:
Original post by ATronic
For example, how would one, step by step, get the decimal number for 5A2FF?




As you know 16 (decimal) is the base of the hexadecimal system. If you wanna convert a hexadecimal to a decimal number, just write your number down like this:


index :43210
number:5A2FF



Then you go from left to right (or vice versa) and multiply each digit with 16^index. Like so:

5 * 16^4 = 327680
A * 16^3 = 40960
2 * 16^2 = 512
F * 16^1 = 240
F * 16^0 = 15
___________________
total = 369407

Then you just from the sum of the resulting numbers.





ATronic
ATronic
THANK YOU!! It all makes sense now. And since I know the value of 1-f in hex, I now know completely how to do hex calculations. You just make my life a lot better. It''s so simple really. I though there was more than that. I thought you had to do something like.

5A2FF
(5^16)*(A^16)*(2^16)*(F^16)*(F^16)=Answer

But it''s not! Yay! Because no matter how hard I looked at the answers to hex equations, I couldn''t understand them if they had more than 2 digits. Thanx again!

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
krez
krez
quote:
Original post by scaught
Am I the only one then that adds hex like I do decimal? eg:
For 0x1a + 0x2c:
a + c = 22 which is a 0x06 and a carried 1
1 + 2 (+ the carried 1) = 4
answer = 0x46
This way when you add things like 0xbeef and 0xf00d (the most edible hex numbers around) you only have to do one large conversion to find the answer (instead of two)

i always forget to carry the "c"...


--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.