From 338d366ea92ad6b0ce8c611cfac7f06459c4b3c4 Mon Sep 17 00:00:00 2001 From: tactonbishop Date: Sat, 3 Dec 2022 11:00:05 +0000 Subject: [PATCH] Last Sync: 2022-12-03 11:00:05 --- .../Binary/Signed_and_unsigned_numbers.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Hardware/Binary/Signed_and_unsigned_numbers.md diff --git a/Hardware/Binary/Signed_and_unsigned_numbers.md b/Hardware/Binary/Signed_and_unsigned_numbers.md new file mode 100644 index 0000000..71821a9 --- /dev/null +++ b/Hardware/Binary/Signed_and_unsigned_numbers.md @@ -0,0 +1,30 @@ +--- +categories: + - Computer Architecture +tags: [binary, binary-encoding] +--- + +# Signed and unsigned numbers + +In order to represent negative integers in binary we use signed numbers. **Signed binary** is basically binary where negative integers can be represented. **Unsigned binary** is standard binary without negative integers. + +## Two's complement + +Signed numbers can be implemented in binary in a number of ways. The differences come down to how you choose to encode the negative integers. A common method is to use "two's complement". + +> The two's complement of a given binary number is its negative equivalent + +For example the two's complement of $0101$ (binary 5) is $1011$. There is a simple algorithm at work to generate the complement for 4-bit number: + +1. Take the unsigned number, and flip the bits. In other words: invert the values, so $0$ becomes $1$ and $1$ becomes $0$. +2. Add one + +// INSERT DIAGRAM HERE + +To translate a signed number to an unsigned number you flip them back and still add one: + +// INSERT DIAGRAM HERE + +### Advantages + +The chief advantage of the two's complement technique of signing numbers is that its circuit implementation is no different from the adding of two unsigned numbers. Once the signing algorithm is applied the addition can be passed through an [adder](/Electronics/Digital_Circuits/Half_adder_and_full_adder.md) comp