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,769
- Website

What is the easiest way to subtract binary in EE?

~meow~

Posting Goal: 2000

#Joe Griffin

Thanks HG for the signature and avatar!!!

Offline

**pwnzor****Member**- From: ca
- Joined: 2018-09-09
- Posts: 25

Just simply replace the gates with doors (or vice versa).

Friendship ended with now is my friend.

<oOo>

/|\ BWRRRRRRRVVVV

/ | \

Offline

**Wooted by:**

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

wait i put this topic in the wrong place help mods

~meow~

Posting Goal: 2000

#Joe Griffin

Thanks HG for the signature and avatar!!!

Offline

**Wooted by:**

**Trytu****Member**- From: Poland
- Joined: 2017-12-10
- Posts: 816

there is special complementary system, that makes adding works same as substracting - just add negative numbers

to add negative number you need to replace all 1 to 0, and all 0 to 1, and then add to result binary 1 (or substract 1, I don't remember)

everytime it'll give you right results

▼example

last carry has to be ignored

overflow can be easily found

if last carry and almost last carry isn't the same, there is an overflow

Thanks to Nikko99 for signature

https: //media.discordapp.net/attachments/402174325349941249/482121641745186816/KHiX2DEFewAAAABJRU5ErkJggg.png

https: //i.imgur.com/YFtzyXA.png

Offline

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

So 1-1 = 0, 1-0 = 1, 0-0 = 0, 0-1 = -1. How can we use that in EE?

~meow~

Posting Goal: 2000

#Joe Griffin

Thanks HG for the signature and avatar!!!

Offline

As Trytu said, the best way to do it is to use two's complement.

Two's complement allows you to represent negative numbers using binary, for example when using 8 bits, the largest bit is taken to mean -128 intead of 128, so rather than having the numbers 0 - 255 you have the numbers -128 - 127.

Converting from positive to negative is simple, you just invert all the bits and add one (or invert all the bits larger than the smallest 1 to do both at the same time)

e.g. 54 = 00110110, flipping all the bits gives you 11001001, adding 1 gives you 11001010 (or alternatively flipping all the bits past the 2s column also gives 11001010)

= 2 + 8 (= 10) + 64 (= 74) - 128 = -54

Once you have numbers in two's complement you can just do normal binary addition on them, and if you want to subtract a number then you just flip its sign then add it. This works because a negative two's complement number is 256 - the positive number, so when adding them they cause an overflow which wraps the result back to the answer you want (47 - 32 = 47 + (256 - 32) = 256 + 15, which overflows and wraps back around to 15)

Offline

**Wooted by: (2)**

LukeM1539273158727930

Pages: **1**

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