Computer hardware recognizes two formats : unsigned and signed
In digital design, an unsigned number is a binary number that represents only magnitude and not the sign. It uses a fixed number of bits to represent a range of non-negative values. The range of values that can be represented by an unsigned number system is always positive and includes 0.
In an unsigned number system, all bits are used to represent the magnitude of the number. For example, in an 8-bit unsigned number system, the range of values that can be represented is 0 to 28 - 1 which is 255. The binary representation of the number 10 in an 8-bit unsigned number system would be 00001010.
Note that there is no negative sign that can be represented. For example, the binary number 1010 represents the decimal number 10 in an unsigned binary system because the leftmost bit is not a sign bit and doesn't represent a negative value.
0000 0000 = 0 0000 0001 = 1 0000 0010 = 2 ... 1111 1110 = 254 1111 1111 = 255
Unsigned numbers are commonly used in digital systems where only positive values are needed, such as counters, timers, and address registers. They can also be used to represent physical quantities that cannot have negative values, such as distance or temperature.
A signed number is a binary number that represents both magnitude and sign. It uses a fixed number of bits to represent a range of numbers that include negative and positive values.
For example, in an 8-bit signed number system, the range of values that can be represented is -28 to 28-1 which makes the range -128 to 127. The two's complement representation of the number -10 would be 11110110, where the leftmost bit indicates that the number is negative, and the remaining bits represent the magnitude of the number (in this case, the magnitude is 10).
0000 0000 = 0 0000 0000 = 1 0000 0010 = 2 ... 0111 1111 = 127 1000 0000 = -128 1000 0001 = -127 ... 1111 1110 = -2 1111 1111 = -1
Note that the leftmost bit of a binary number represents the sign of the number: 0 for a positive number and 1 for a negative number using the two's complement notation. The remaining bits represent the magnitude of the number. For example, the signed binary number 11010101 represents the decimal number -43 using the two's complement of the binary number, because the leftmost bit is 1, and the magnitude of the number is 010101, which is equal to the decimal number 21.
Signed binary numbers provide a more comprehensive way of representing numbers because they can represent both positive and negative numbers in a compact format.
Convert unsigned binary to decimal
An unsigned number is a binary number that represents a positive value. The range of unsigned numbers depends on the number of bits used to represent them. For example, an 8-bit unsigned number can represent values from 0 to 255.
Here is an example of an 8-bit unsigned number: 10110110. This binary number represents a value in base 10 by adding up the weight of each bit that is turned on (1). For an 8-bit number, the weights are powers of 2 from 20 to 27. So, we have:
1 0 1 1 0 1 1 0 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0 128 0 32 16 0 4 2 0
Adding up these weights, we get: 10110110 = 128 + 32 + 16 + 4 + 2 = 182. Therefore, the unsigned binary number 10110110 represents the positive decimal number 182.
Convert signed binary to decimal
The most significant bit (MSB) is used as the sign bit, where 0 represents positive, and 1 represents negative. The remaining bits represent the magnitude or absolute value of the number.
For example, let's suppose we want to represent the decimal number -46 in signed magnitude form using 8 bits. The absolute value of 46 in binary is 00101110. To represent -46, we set the MSB to 1, indicating a negative number, resulting in the signed magnitude binary representation of 10101110.
Here is how to convert a signed magnitude binary number to decimal:
- Check the MSB bit.
- If it is 0, the number is positive, and we can find its value by multiplying each bit's weight by its value, adding up the results.
- If it is 1, the number is negative, and we invert all the bits (changing 1 to 0 and 0 to 1) in the remaining bits.
- We then find the decimal value of the inverted binary number and add a negative sign to it.
For example, let's convert the signed magnitude binary number 11011010 to decimal:
- The MSB is 1, so the number is negative.
- Invert the remaining bits to get 00100101.
- Find the decimal value of the inverted binary number by multiplying each bit's weight by its value, adding up the results. This gives us 1 x 32 + 0 x 16 + 0 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 37.
- Add a negative sign to the result to get -37. Therefore, the signed magnitude binary number 11011010 is equal to -37 in decimal.