0 Users appreciate this thread.
How to: Binary Math
djl12328 (2013-02-15 16:31:22)The topic is edited to fix that. -Gray
I'll add that later when I have more time. -Void
www.dark-isle.weebly.com
Log in to submit a comment
Back to forum: Programming (Python, Java, Delphi/Pascal, C, VB, etc)
New registered users today: 7
Newest registered user: ElegantVulpes
I said in an earlier topic that I would make a full doc on how to do binary math, so here it is.
I'll start this off by describing what Binary is. Binary is a base 2 number system. What a base 2 number system is, is well, a number system with only 2 digits in it. 0, and 1. Our main number system that we use in ordinary life is a base 10 number system, so it includes 10 different digits. 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. There is also a base 16 number system I know of called Hexadecimal, which I will go into later.
Let's begin with the two most simple math functions, Addition and Subtraction. The rules of addition are 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0 (And carry a one).
Example:
111 <-- These are the carried numbers 01001010 (74) +10100111 (167) ---------- 11110001 (241)
Subtraction is exactly the same, except you have to convert the second number to it's negative equivalent. To convert a number you have to turn every 1 to a 0, and every 0 to a 1. Then add 1 to it.
Example:
10010101 = 01101010 01101010 + 1 ----------- 01101011
After you convert it, you just have to add the two numbers together. I am going to run through the rules of a few other math functions really quickly, so here I go. I put them in spoilers to save space.
0 + 0 = 0
0 + 1 = 0
1 + 0 = 0
1 + 1 = 1
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 1
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0
0 + 0 = 1
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0
0 + 0 = 1
0 + 1 = 0
1 + 0 = 0
1 + 1 = 0
Hopefully, you were able to understand how to do all that, and that you learned something from that.
2013-02-15 16:29:12