Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**ILikeTofuuJoe****Member**- From: Obvervable Universe
- Joined: 2018-06-04
- Posts: 1,767
- Website

Binary is the most compact way of representing numbers. But its calculation is a bit complex.**Binary Addition**

In this section we will use 5+7 as an example. 5 = 101 and 7 = 111. Add them up together in binary and you'll get 1100(12). Let's take a look at how the binary calculator is going to accomplish that. So first of all, you need to let your calculator know that 1+1=10,1+0=1,0+1=1,and0+0=0. You need to do that for every bit. 1+1 is fairly tricky compared to the others. Because it advances a bit. You'll need to check that digit to see if it equals 1. If yes, change that to 0 an

▼View

**Binary Subtraction**

this section we will use 9-3 as an example. 9 = 1001, 6 = 110, 9-6 = 11This is a bit trickier than the addition, but is simpler than multiplication and division. First, know that 1-1 = 0, 1-0 = 0, 0-1 = -1, 0-0 = 0. Subtract each bit and you'll get 10(-1)0. Since -1 is not a part of binary bits, We'll have to get rid of it. From the -1, check the left number. If it is 1, change it to 0 and the bit itself to 1. If it is -1, then continue looking left, when 1 is found, drop down the chain of -1s until your original bit. If it is 0, or if your chain of -1s has 0s in it, continue searching. When a 1 is found, change it to 1 if there are -1s after it(It gives 1 to the -1), If there aren't -1s after it, don't do anything. Alright let's test! Step 1: Subtract bits 1001 - 110 = 1(-1)(-1)1. Step 2: Clearing -1s: rightmost -1: the left is a -1, So it has to be 1. Leftmost -1: The right is a -1, the left is a 1. Take the 1 and give it to the right -1. Step 3: Answer! 1001 - 110 = 11!

P.S.: I forgot to take screenshots...

~meow~

Posting Goal: 2000

#Joe Griffin

Thanks HG for the signature and avatar!!!

Offline

**JadElClemens****Member**- From: Colorado, USA
- Joined: 2015-02-15
- Posts: 4,559

Good post! I'll add that computers largely do not actually subtract binary values. Negative values in binary are, in most cases, represented as a two's complement value, where the most significant bit (the leftmost bit in most representations) is the sign bit - 0 for positive, 1 for negative. When using a signed integer of this type, subtraction is performed as the addition of two numbers where at least one is negative, because the rules are actually the same.

▼Quick rundown on calculating two's complement values

For example, take the calculation 10 + (-3). Normally you could represent 10 in 4 bits, but since we need the MSB to be a sign bit we have to use at least 5.

```
01010 (10)
+ 11101 (-3)
-----------------
00111 ( 7)
```

Technically this does overflow (the output value is 100111 = -25, but since we're using 5-bit hardware in this example we have to throw out the MSB). At this moment I don't remember the rules for when overflow should be ignored.

I hate tall signatures.

Offline

**Wooted by: (2)**

**ILikeTofuuJoe****Member**- From: Obvervable Universe
- Joined: 2018-06-04
- Posts: 1,767
- Website

^ Alright! I'll add some text for calculation negative numbers (as soon as i figure out how to do that).

So for binary numbers, value = (non sign bits' sum) - sign bit?

~meow~

Posting Goal: 2000

#Joe Griffin

Thanks HG for the signature and avatar!!!

Offline

ILikeTofuuJoe wrote:

^ Alright! I'll add some text for calculation negative numbers (as soon as i figure out how to do that).

So for binary numbers, value = (non sign bits' sum) - sign bit?

The most significant bit counts for negative what it used to, yes. So if it was an 8 bit number then the most significant bit would be -128 instead of 128, and the rest of the bits would stay the same.

The easiest way to negate a number that I know of is to flip all the bits then add one (effectively flipping all the bits after the first one from right to left):

34 = 00100010

-> 11011101

+ 00000001

= 11011110

= -128 + 64 + 16 + 8 + 4 + 2 = -34

Offline

LukeM1553860505743927

Pages: **1**

[ Started around 1594875975.0213 - Generated in 0.026 seconds, 10 queries executed - Memory usage: 1.36 MiB (Peak: 1.48 MiB) ]