SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 09/12/2013, 04:52 PM   #1
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Converting Binary to Decimals and other way around (Easy)

Tutorial
Converting Binary to decimals


Hello welcome to my third tutorial, this time i will try to explain the easiest way to convert binary numbers
to regular decimals and the other way around.
I learned this at school the other day and I thought i'd share it with you guys
(+ I didn't find any of these tutorials on the SA-MP forums). The way i'm going to show you is the easiest way according to my teacher.


Lets get started at the beginning, I am going to try to explain a tiny bit of what binary means and how it works.

If you do not know anything about binary than thats no problem.

The Tutorial:

Computers read one's and zero's and this is what binary excists off, in some ways it can mean this:
pawn Code:
1 = True or Yes
0 = Not true or false
A example in SA-MP can be in your server CFG
pawn Code:
...
Announce 1 //So this means it will announce you're server, 0 would mean that it won't announce it.
...
Now you probably are asking you're self "What does binary look like?", here's a example:
pawn Code:
10110111
//As you notice the number is 8 digits long, this is a default binary number.
Next we are going to take a look at bits, to convert binary to decimals you need to know how this works.
Same as there are 8 digits in binary there are 8 numbers of bits.
pawn Code:
128   64    32    16    8    4    2   1
/*looks familiar? they should because you're windows also has different verions (32 bit and 64 bit versions)
If you add all these numbers together you will also get a familiar numbers which is 256, this number has to do with a IP Adres (you're gateway). anyway lets move on to the actuall converting part!*/
To convert binary to decimals we are going to place the 8 digit binary number under these 8 numbers of bites,
it looks likes this:
pawn Code:
128   64    32    16    8    4    2   1

1     0     1      1     0    1   1   1
/*Maybe you can already guess what we are going to do, if you payed attention to what the one's and zero's mean.
If you forgot (1 means true and 0 means false).*/
Converting the binary:

I won't talk to much anymore, here's what converting it actually looks like:
pawn Code:
//If theres a 1 under a bite than it means its true so add it to the other bits where a 1 is under.
1 =  1 = 1
2 =  1 = 3
4 =  1 = 7
8 =  0 = dont count it
16 = 1 =  23
32 = 1 =  55
64 = 0 = dont count it
128 = 1 = 83
//everything adds up to 183 so our conclusing is that the binary number 10110111, is in regular decimals 183.

Converting decimals to binary

Basicly to convert a regular decimal to binary you will do the same as above but the other way around,
example:
pawn Code:
//We want to convert the number 240 to binary, we take the 8 bit numbers again:
128   64    32    16    8    4    2   1
//And now we will go from right to left to see what numbers of bits we need to get 240, so:
128 = 1
64 = 1
32 = 1
16 = 1
8 = 0
4 = 0
2 = 0
1 = 0
//So 240 in binary is 11110000
Well this is the end of my tutorial and I hope you learned something of it! I hope i was clear enough and if you have any questions feel free to leave a comment!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse

Last edited by Voxel; 12/12/2013 at 08:30 AM.
Voxel is offline   Reply With Quote
Old 09/12/2013, 05:24 PM   #2
Ada32
Huge Clucker
 
Ada32's Avatar
 
Join Date: Apr 2013
Posts: 293
Reputation: 62
Default Re: Converting Binary to Numbers and other way around (Easy)

thread titles wrong, because binary is a numeral system you can't convert binary to numbers, just doesn't make sense..(to base-10/decimal?) and we already have a thread here
Ada32 is offline   Reply With Quote
Old 09/12/2013, 06:22 PM   #3
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Converting Binary to Numbers and other way around (Easy)

Quote:
Originally Posted by Ada32 View Post
thread titles wrong, because binary is a numeral system you can't convert binary to numbers, just doesn't make sense..(to base-10/decimal?) and we already have a thread here
It does make sense, I had this on school and if you get something on school it is probably legit or am I getting scr*wed by my teachers? I dont think so. This is correct as far as I know, if anyone else with more experience in this can comment here than that would be great! And the thread title is not wrong.
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 09/12/2013, 09:43 PM   #4
Infinity
High-roller
 
Infinity's Avatar
 
Join Date: Jul 2009
Posts: 1,222
Reputation: 975
Default Re: Converting Binary to Numbers and other way around (Easy)

What he meant is that you can't convert binary representations to 'numbers', as binary numbers ARE numbers. You meant 'converting to decimal representation'.

Also, instead of limiting the tutorial to 128, you can generalize it by explaining that 1001.....1 equals 2^n-1 + ... + 2^0, where n is the length of the binary string.
__________________

I apologize for the stupidity of my fellow members

Quote:
Originally Posted by !damo!spiderman View Post
Stand for something that's going to help the world rather than fill it with more hate. Give someone a hug, tell someone you care... Do something, do anything but do it with love not hate.
Infinity is offline   Reply With Quote
Old 10/12/2013, 05:16 AM   #5
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Converting Binary to Numbers and other way around (Easy)

Quote:
Originally Posted by Infinity View Post
What he meant is that you can't convert binary representations to 'numbers', as binary numbers ARE numbers. You meant 'converting to decimal representation'.

Also, instead of limiting the tutorial to 128, you can generalize it by explaining that 1001.....1 equals 2^n-1 + ... + 2^0, where n is the length of the binary string.
On school they didn't go to far into this, i only learned how to do this thanks for you're reply!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 11/12/2013, 10:42 AM   #6
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Converting Binary to Numbers and other way around (Easy)

Bump! Anyone else?
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 12/12/2013, 04:38 AM   #7
Kyosaur
Gangsta
 
Kyosaur's Avatar
 
Join Date: Mar 2008
Location: USA - California
Posts: 973
Reputation: 349
Default Re: Converting Binary to Numbers and other way around (Easy)

Quote:
Originally Posted by Voxel View Post
It does make sense, I had this on school and if you get something on school it is probably legit or am I getting scr*wed by my teachers? I dont think so. This is correct as far as I know, if anyone else with more experience in this can comment here than that would be great! And the thread title is not wrong.
Do I count as someone with "more experience" lol? He is correct in saying that the tittle doesn't really make sense. You are not "converting binary to numbers", as they are already numbers, and you are not really manipulating anything; if anything you are attempting to explain the mathematical notation that represents numbers (base 2, or binary, in this case).

You should also REALLY learn to take criticism to better your posts. Since you don't seem to take it very well, I am not even going to go into the issues with your post. I will say however, that you should only write tutorials on subjects you are pretty knowledgeable about, or at LEAST plan on researching a ton (dont mean this to sound mean, but its good advice).

Last edited by Kyosaur; 12/12/2013 at 05:16 AM.
Kyosaur is offline   Reply With Quote
Old 12/12/2013, 07:06 AM   #8
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Converting Binary to Numbers and other way around (Easy)

Quote:
Originally Posted by Kyosaur View Post
Do I count as someone with "more experience" lol? He is correct in saying that the tittle doesn't really make sense. You are not "converting binary to numbers", as they are already numbers, and you are not really manipulating anything; if anything you are attempting to explain the mathematical notation that represents numbers (base 2, or binary, in this case).

You should also REALLY learn to take criticism to better your posts. Since you don't seem to take it very well, I am not even going to go into the issues with your post. I will say however, that you should only write tutorials on subjects you are pretty knowledgeable about, or at LEAST plan on researching a ton (dont mean this to sound mean, but its good advice).
I do take criticism well but on the internet it can be understood wrong as you cant see my facial expression, and I will admit that I didn't know how to call this topic so yeah :X I just wanted to share my knowledge on how to convert binary to decimals then (or what ever its called)

anyway, thanks for your reply!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 12/12/2013, 07:23 AM   #9
BigETI
Banned
 
Join Date: Mar 2010
Location: Germany
Posts: 1,046
Reputation: 359
Default AW: Converting Binary to Numbers and other way around (Easy)

Representation does not equal conversion. Please change the title's name
BigETI is offline   Reply With Quote
Old 12/12/2013, 08:27 AM   #10
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: AW: Converting Binary to Numbers and other way around (Easy)

Quote:
Originally Posted by BigETI View Post
Representation does not equal conversion. Please change the title's name
Changed.
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] An in-depth look at binary and binary operators. Kyosaur Tutorials 51 01/08/2013 08:41 PM
Binary D: MP2 Scripting Help 6 19/07/2012 01:00 PM
binary stuff converting and whatnot WillyP Help Archive 8 30/10/2010 10:54 PM
Convert string with numbers into numbers only? The_Moddler Help Archive 6 17/10/2010 09:20 AM
Storing Player Numbers In MYSQL Without Two Numbers Being The Same Kenny990 Help Archive 3 29/06/2009 02:10 AM


All times are GMT. The time now is 02:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.