Numbering System Conversions

DON'T post new tutorials here! Please use the "Pending Submissions" board so the staff can review them first.
Post Reply
User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Numbering System Conversions

Post by Gogeta70 »

Hey, everyone. In this topic, i will explain how to convert from certain numbering systems and back again manually, though a calculator may be handy.

Decimal - Hexadecimal

Code: Select all

decimal: 1532

(highest power of 16 less than 1532)
1532/16^2 = 5 (drop decimals)

5 = 1st character of hex character.

5*16^2 = 1280 (take first hex char, multiply by previous power)
1532 - 1280 = 252 (subtract from initial number)

Find highest power of 16 under 252. This is 16^1, or simply 16.

252/16 = 15 (because of how hex is, A comes after 9, then B, then C all the way to F. Then it goes 1A, etc.)

15 = F
So, 5F...

15*16 = 240
252 - 240 = 12

Highest power of 16 that is lower than 12 is 16^0, which is 1.

12/1 = 12
In hex, 12 = C.

so 5FC.
Hexadecimal to Decimal

Code: Select all

Let's use our previous Hex, 5FC.

5 = 5
F = 15
C = 12

We have 3 elements, and counting 0, that means we must start with a power of 2.
2, 1, and 0. 3 powers.

So...

first hex number, 5
5*16^2 = 1280

Second hex number = 15
15*16^1 = 240
1280 + 240 = 1520

(notice how the powers are decreasing by 1 each time?)

Third hex number = 12
12*16^0 = 12
12 + 1520 = 1532

5FC = 1532
Decimal (ASCII) to Binary

Code: Select all

Let's take the decimal number 132.
The way we're going to convert this to binary is very similar to the previous examples.
First, we want to find the greatest power of 2 that's less than 132. This would be 2^7, or 128.

132 - 128 = 4 (because we didn't get a negative value, this would be 1)
(now, divide 128 by 2)
4 - 64 = -60 = (0 in binary, because it's negative.)
4 - 32 = -28 = 0
4 - 16 = -12 = 0
4 - 8 = -4 = 0
4 - 4 = 0 = 1 (gives us 0, but it isn't a negative number, so it's a binary 1.)
0 - 2 = -2 = 0 (we subtracted that 4 from 4, and we have to keep dividing until we get the power to zero.)
0 - 1 = -1 = 0

So, 132 in binary is as follows: 10000100
Binary to Decimal

Code: Select all

This is a bit harder to explain.
Basically , starting at the right-most character in binary, we increase by powers of 2.
For instance, let's use the previous example. 10000100. Turn it sideways, like this:

1
0
0
0
0
1
0
0

And multiply, like this.

1 * 128
0 * 64
0 * 32
0 * 16
0 * 8
1 * 4
0 * 2
0 * 1
Notice a pattern? They always multiply by 2 to increase. 4*2 = 8, 8*2 = 16, etc. The left most character in binary will be multiplied by the highest value, and the right most value in binary, multiplied by 1.

128 + 4 = 132.
If you don't understand something here, please feel free to post a question.
Last edited by Gogeta70 on 22 Mar 2007, 00:16, edited 1 time in total.
¯\_(ツ)_/¯ It works on my machine...

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

A good post of assembly starters.. but you forgot to mention binary to hexadecimal and vice versa which can be very useful for assembly programmers.... but i m too lazy to show and i rather use my scientific calculator..
:roll:

ebrizzlez
Kage
Kage
Posts: 732
Joined: 31 Mar 2007, 16:00
17
Location: Hidden in a Buffer Protection.
Contact:

Post by ebrizzlez »

Thanks for the info, and I would have a question. What use is this for? I mean, when would you need to know this stuff. I know people use to program in binary, but not anymore. So when does this info come in handy? thanks. :wink:
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

Notice a pattern? They always multiply by 2 to increase. 4*2 = 8, 8*2 = 16, etc. The left most character in binary will be multiplied by the highest value, and the right most value in binary, multiplied by 1.
In fact, the pattern is 2^N n start at 0 :)
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

ebrizzlez wrote:Thanks for the info, and I would have a question. What use is this for? I mean, when would you need to know this stuff. I know people use to program in binary, but not anymore. So when does this info come in handy? thanks. :wink:
Dude thats the basics.. every good computer guy would know this... and talk of application? Encryption makes extensive use of all this, error checking/correcting mechanisms have parity bits and all, everything is at the bit level, you gotta know them, without them you cant code...

ebrizzlez
Kage
Kage
Posts: 732
Joined: 31 Mar 2007, 16:00
17
Location: Hidden in a Buffer Protection.
Contact:

Post by ebrizzlez »

Well.. I would understand encyption, but when your debugging code, what do you use.. a debugger. And you dont look at binary, but rather you look at allocation of memory and some hex, maybe a little decimal. Not trying to argue, never in my computer lifetime have I needed to know any of this stuff to do something. I was just wondering. And now I know. Thanks. :wink:
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

This comes in handy and many programmers / engineers need to know how to convert numbers while writing code / designing circuits.

If you desire to make fast efficient code and wish to address some lower level concerns then you must learn the basic fundamentals of base 2, base 16 etc. How to convert the basses and use the numbers correctly in your program is going to come about. Most frequently in Assembly and C, but others as well.

Most importantly it gives the programmer a greater wisdom / knowledge of the computer and or electronic device that he or she is manipulating in order to achieve the goal that is desired.
₣£ΘΘĐĦΘŮŇĐ

ebrizzlez
Kage
Kage
Posts: 732
Joined: 31 Mar 2007, 16:00
17
Location: Hidden in a Buffer Protection.
Contact:

Post by ebrizzlez »

I seee... thanks psuedo and floodhound, I never knew that. But then again, I never did low level coding. :roll:
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]

User avatar
babyrusher
Newbie
Newbie
Posts: 1
Joined: 02 Nov 2007, 17:00
16

Post by babyrusher »

thanks man iam from germany and i have this actually at school strangely i understand this better then in german at school ^^

User avatar
Still_Learning
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 1040
Joined: 11 Jun 2008, 16:00
15
Location: Trigger City

Post by Still_Learning »

Nice thread, thanks
Gone

User avatar
computathug
Administrator
Administrator
Posts: 2693
Joined: 29 Mar 2007, 16:00
17
Location: UK
Contact:

Post by computathug »

babyrusher wrote:thanks man iam from germany and i have this actually at school strangely i understand this better then in german at school ^^
Hey babyrusher, welcome to suck-o!

As you can see we have a dedicated part of the forum for people who speak German. You might also like to know the site owner is from Germany too.

Why not introduce yourself in the introductory thread which can be found here...

https://www.suck-o.com/modules.php?name ... topic&t=26

Enjoy your stay :wink:

Post Reply