Official Everybody Edits Forums

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.

Advertisement

Hello, visitor! These forums are run off of the revenue generated from these ads. If you'd like to support us, please whitelist us or consider donating:

#1 2018-10-09 05:19:18

ILikeTofuuJoe
Banned
From: Obvervable Universe
Joined: 2018-06-04
Posts: 1,239
Website

Subtracting binary

What is the easiest way to subtract binary in EE?


https://wiki.everybodyedits.com/images/8/8f/117_cat ~meow~ https://wiki.everybodyedits.com/images/8/8f/117_cat
Posting Goal: 2000
#Joe Griffin
Signature
Thanks HG for the signature and avatar!!!

Offline

#2 2018-10-09 05:20:23

pwnzor
New Member
From: ca
Joined: 2018-09-09
Posts: 7

Re: Subtracting binary

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


Friendship ended with https://wiki.everybodyedits.com/images/9/9c/010_shades now https://wiki.everybodyedits.com/images/5/58/040_ghost is my friend.

Offline

Wooted by:

#3 2018-10-09 05:22:00

ILikeTofuuJoe
Banned
From: Obvervable Universe
Joined: 2018-06-04
Posts: 1,239
Website

Re: Subtracting binary

wait i put this topic in the wrong place help mods


https://wiki.everybodyedits.com/images/8/8f/117_cat ~meow~ https://wiki.everybodyedits.com/images/8/8f/117_cat
Posting Goal: 2000
#Joe Griffin
Signature
Thanks HG for the signature and avatar!!!

Offline

Wooted by:

#4 2018-10-09 16:05:38

Trytu
Member
From: Poland
Joined: 2017-12-10
Posts: 435

Re: Subtracting binary

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

Last edited by Trytu (2018-10-09 16:07:11)


KHiX2DEFewAAAABJRU5ErkJggg.png

Offline

#5 2018-10-10 17:49:55

Slabdrill
Formerly 12345678908642
From: canada
Joined: 2015-08-15
Posts: 2,794
Website

Re: Subtracting binary

In the same way you add


suddenly random sig change

Offline

#6 2018-10-11 05:21:50

ILikeTofuuJoe
Banned
From: Obvervable Universe
Joined: 2018-06-04
Posts: 1,239
Website

Re: Subtracting binary

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


https://wiki.everybodyedits.com/images/8/8f/117_cat ~meow~ https://wiki.everybodyedits.com/images/8/8f/117_cat
Posting Goal: 2000
#Joe Griffin
Signature
Thanks HG for the signature and avatar!!!

Offline

#7 2018-10-11 16:52:38

LukeM
Dev Team
From: England
Joined: 2016-06-03
Posts: 2,435
Website

Re: Subtracting binary

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:
LukeM1539273158727930

Board footer

Powered by FluxBB

[ Started around 1540202194.5174 - Generated in 0.028 seconds, 13 queries executed - Memory usage: 1.2 MiB (Peak: 1.31 MiB) ]