SRL Archive - Computer Help and Tutorials

How To Calculate Binary, Decimal, Hexadecimal


Nadeem

2009-05-16 05:35:42

Hello Ladies & Gentlemen! :)

[Binary (Base2)]
This is the most depth down programming that exists, its is the FINAL actual result that ALL other languages are converted into before read by a computer. The principal of all programming.

[Calculating]:
Basically, Binary code are made up from the remainders of a sequence of numbers divided by 2, which is why its also called the Base2 code.

[Example]:
Base 10 Code: 26510

Step 1: Divide by 2.
Step 2: Take count of the remainder.
Step 3: Keep repeating step 1 until you reach 0.

265/2 = 132 R = 1 ^
132/2 = 066 R = 0 |
066/2 = 033 R = 0 |
033/2 = 016 R = 1 |
016/2 = 008 R = 0 |
008/2 = 004 R = 0 |
004/2 = 002 R = 0 |
002/2 = 001 R = 0 |
001/2 = 000 R = 1 | Read up this way.

Remainders put together: 100001001 ~ Now we need to divide them into chunks of 4 starting from the end, and fill in 0's to take place if we have remaining space.

Binary Code = 0001 0000 1001

[Decimal (Base10)]
This is basically the second another type of code that is later converted into the basic Binary before the computer reads it. It is more simpler and easier to understand from a code perspective compared to Binary.

[Calculating]:
This is a sequence that involves using power base of 2 on the Binary Code. If you noticed, we divided everything by 2 in order to convert from Decimal to Binary, therefore in order to revert back we must do the opposite of dividing which is powering it.

[Example]:
Base2 Code: 0100 1110

Step 1: You must assign a power by 2^count starting from the end to the beginning.
Step 2: Skip the 0's.
Step 3: Calculate the powered value.
Step 4: Repeat Step 3 until you reach the first value
Step 5: Add up the sum.

0 ~ 2^0 - Skip since this is a 0
1 ~ 2^1
1 ~ 2^2
1 ~ 2^3

0 ~ 2^4 - Skip since this is a 0
0 ~ 2^5 - Skip since this is a 0
1 ~ 2^6
0 ~ 2^7 - Skip since this is a 0

2^1 = 2
2^2 = 4
2^3 = 8
2^6 = 64
SUM = 78

Decimal Code = 7810

[Hexadecimal (Base16)]
This is the most commonly seen computer code. This is the type of code that is used to represent RGB colors. In Hexadecimal codes, usually we see letters aswell as numbers, these letters are used as a way to represent a block of 2 numbers. Since computer code can only read upto 1 block of number per slot. We cannot put something like '11' into one block of code since thats taking up 2 slots and will have a whole new different meaning, which is why we replace '11' with a capital 'B'.

[Legend]:
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15

[Calculating]:
This is a basically the same method as calculating Binary and Decimal, except you use 16 instead of a 2.

[Example]:
Base10 Code: 24410

Step 1: Divide code by 16
Step 2: Take count of the closest division number that can go into the Base10 Code 16 times
Step 3: Then take the original Base10 Code you started with and subtract that by the number you got from Step 2

244 / 016 = 015 <— This is the number you'll need to replace with a letter since it is larger than 9 taking up 2 slots.
016 * 015 = 240 <— You need this for the last step.
244 - 240 = 004 <— The remainder is going to be the last digit.

Hexadecimal Put Together = F416
Hexadecimal Code = 0xF416 <— Standard way of represeting a Hexadecimal code, this code in RGB is known to print out a light gray color



Thank you for reading my tutorial! :D
- Nadeem




~NS

Mystic

2009-05-16 07:13:14

Wow, Nadeem, you know your stuff. Great Guide!
I might learn this after all ;)

Nadeem

2009-05-16 07:44:06

Haha thanks! :)



~NS

Da 0wner

2009-05-16 09:25:21

Lol nice noob. :p

ShowerThoughts

2009-05-16 10:58:55

Nice, I understand binary, I understand decimal but not the hex, or I do but I didn't know it yet.:p

Pure1993

2009-05-16 12:17:06

Lol, great stuff, now I can write my answers in math in a bianary code… our teacher is a former IT person, so yeah, he should figure it out. ;)

Floor66

2009-05-16 14:16:09

I don't get shit of it but it looks kwl :p

Nadeem

2009-05-17 02:08:11

Thank you guys! :D If you want me to explain something which you do not understand let me know and I can help if you wish :P



~NS

marpis

2009-06-16 23:23:04

this works with all numbers between 2 and 10 btw :)
with this technique you can calculate base7 or base4, for example

Nadeem

2009-06-16 23:47:57

From: marpis
this works with all numbers between 2 and 10 btw :)
with this technique you can calculate base7 or base4, for example


Yes, these are just the most common ones :)



~NS

Atlanta

2009-07-12 03:40:27

Thanks for the tut, no seriously it's helped me out.
I only read the subsection on hexadecimal but it's really helped :D

If I were you I would maybe add somewhere that: the max integer that a hexadecimal unit can represent is 255.

Please note though, if you have already included this somewhere else in the tut; like mentioned, I only read the hexadecimal subsection.

Da 0wner

2009-07-12 03:48:38

FF = 255.

But 255 is not the maximum….you can have more.

Atlanta

2009-07-12 03:51:25

Yeah I know 0xFF = 255, but how can you have more? isn't it limited to 0x##?
And also, coming from a web development background, #FFFFFF = 255, 255, 255

Da 0wner

2009-07-12 04:05:15

Yep, hex RGB value is written like that. Six hex numbers split up into 3 values (r, g, and b).

#FFFFF = Black.

But 0xFFFF = 65535, 0xFFF = 4095 etc.

You can have virtually any number.