Aman
So adding 2's complement of -8 to binary numbers will give wrong result
Aman
Binary -8 => 10001000 2's complement -8 =>11111000
Aman
-8 + 12 should give u 4 whose binary is 00000100
Aman
Oh yes
Mat
Wait
Aman
So the 1 is coming additional
BinaryByter
I feel like my NN isnt learning that *certain* words are german, but that LONG words are german
BinaryByter
;_;
Mat
Count the bits
Mat
And the input?
Mat
If input is 8 bit long, output is 8 bit long
Mat
The 9th is cutted
Mat
That's overflow
Mat
No problem ;)
Alignant
Do they make you solve it at school?
Alignant
Wozniak
Mat
Hey
Mat
New member? Read the pinned message
Mat
:D
Mat
What? Show me the operation using monospaced format
Mat
Mmm, no?
Mat
https://en.wikipedia.org/wiki/Two%27s_complement
Mat
You've written a different number up there
Alignant
Here, play with it :D
Alignant
#include <iostream> #include <bitset> int sign(const int a) { return a > 0 ? ~a + 1: a; } int main() { const int a = 11; const int b = sign(a); std::cout << a << " -> " << b << "\n"; std::cout << std::bitset<8>(a) << " -> " << std::bitset<8>(b) << "\n"; std::cout << "a + b = " << a + b << "\n"; return 0; }
Alignant
Result: 11 -> -11 00001011 -> 11110101 a + b = 0
Mat
You need to use the same number of bits
Mat
Inputs and output have the same number of bits
Mat
No
Mat
0100100+ 1101100 ------- 1|0010000
Mat
You CUT the overflow
Mat
You don't change nothing
Mat
No
Mat
You're starting from a bad point
Mat
You can't sum numbers with a different number of bits in notation
Mat
36 is either 0100100, 00000000000000100100 or 00100100, but NOT 100100
Mat
36 is either 0100100, 00000000000000100100 or 00100100, but NOT 100100
Last one is, as an unsigned, 36. The others are +36 if ints, or 36 as unsigned
Mat
So it can't be rapresented in Two's complement
Mat
You need more bits
Mat
Like 011111111
Mat
-255 is at least 100000000
Mat
55 is something that you'll do
BinaryByter
-255 is at least 100000000
-255 is not encodable in 8 bit
BinaryByter
yea
BinaryByter
no, -255 would be 111111111
BinaryByter
where the first bit represents the sign
BinaryByter
practically you usually put the sign bit way upfront
BinaryByter
100000000 00000000 00000000 11111111
BinaryByter
oh yea
olli
no, -127 would be 11111111
olli
7 bits represent the number => [0, 127] 1 bit for the sign
Alignant
oh yea
He means that 11111111 means 255 if it's an unsigned char
olli
again you cannot represent -255 with 8 bits
olli
sorry?
BinaryByter
not at all
BinaryByter
you need atleast a bitfield of 9 bytes
olli
using 9 bits (one's complement) (range [-255, 255]) -255 would be 1 1111 1111 255 would be 0 1111 1111 using two's complement (range [-256, 255]) -255 would be 1 000 0001 255 would be 0 1111 1111 by duplication of the first bit yo can keep the same value with larger bitfields
Григорий
100000000 + 000110111
olli
you can play with it here http://www.binaryconvert.com/result_signed_int.html?decimal=045050053053
Alignant
Lol
Alignant
#include <iostream> #include <bitset> typedef std::bitset<16> bits; int change_sign(const int a) { return ~a + 1; } int main() { const int a = 255; const int b = change_sign(a); std::cout << bits(a) << " -> " << a << "\n" << bits(b) << " -> " << b << "\n\n"; std::cout << " " << bits(a) << "\n" << " " << bits(b) << "\n" << " -------- + \n" << "1|" << bits(a + b) << std::endl; return 0; }
Alignant
Result: 0000000011111111 -> 255 1111111100000001 -> -255 0000000011111111 1111111100000001 -------- + 1|0000000000000000
Alignant
Never mind, I'm just messing around
olli
1 0000 0001 ( -255) + 0 0011 0111 (55) ----------- 1 0011 1000 (-200)
BinaryByter
so I have my SFINAE container that returns true, but how can I make it return false if it fails?
Alignant
-255 -> 11111111 11111111 11111111 00000001 55 -> 00000000 00000000 00000000 00110111 -200 -> 11111111 11111111 11111111 00111000 What's wtong about that? :D
BinaryByter
dudes stop discussing binary, I have two hours of music theory later on and I don't want to have an headhache when doing that xD
BinaryByter
STAWP
BinaryByter
xD
Alignant
STAWP
Now it's a binary channel. I want to rename it to 0/1
Anonymous
i was just gonna ask about bitstring representation of sets
BinaryByter
music theory is only in about 2 hours