Username:
Password:
Remember me:
Register

Back to forum: Programming (Python, Java, Delphi/Pascal, C, VB, etc)


Search forums via Google


0 Users appreciate this thread.

How to: Binary Math
Started by djl12328
(2012-11-04 20:22:53)
djl12328 (2012-11-04 20:22:53)
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:
Source Code
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:
Source Code
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.

AND show

0 + 0 = 0
0 + 1 = 0
1 + 0 = 0
1 + 1 = 1


OR show

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 1


XOR show

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0


NAND show

0 + 0 = 1
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0


NOR show

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.

This post has been edited one or more times, the last time was:
2013-02-15 16:29:12

www.dark-isle.weebly.com
djl12328 (2013-01-27 19:14:16)
Yes. -doggle
www.dark-isle.weebly.com
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

This topic's ID: 35508

Back to forum: Programming (Python, Java, Delphi/Pascal, C, VB, etc)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved