09.12.2013, 16:52
(
Последний раз редактировалось Voxel; 12.12.2013 в 08:30.
)
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:
A example in SA-MP can be in your server CFG
Now you probably are asking you're self "What does binary look like?", here's a example:
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.
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:
Converting the binary:
I won't talk to much anymore, here's what converting it actually looks like:
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:
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!
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 Код:
1 = True or Yes
0 = Not true or false
pawn Код:
...
Announce 1 //So this means it will announce you're server, 0 would mean that it won't announce it.
...
pawn Код:
10110111
//As you notice the number is 8 digits long, this is a default binary number.
Same as there are 8 digits in binary there are 8 numbers of bits.
pawn Код:
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!*/
it looks likes this:
pawn Код:
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).*/
I won't talk to much anymore, here's what converting it actually looks like:
pawn Код:
//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.
Basicly to convert a regular decimal to binary you will do the same as above but the other way around,
example:
pawn Код:
//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