Converting Negative Decimal To Binary
Answer : You're confused because you forgot that there must be something that distinguishes positive numbers from negative ones. Let's say you want to store non-negative numbers on 8 bits. 00000000 is 0, 00000001 is 1, 00000010 is 2, 00000011 is 3, 00000100 is 4, ... 11111111 is 255 So you can store numbers in range 0-255 on 8 bits. 255 = 2 8 - 1. (2 is the base of binary system, 8 is the number of bits, 1 is subtracted because we want to count 0 in) Now, let's say you want to store negative numbers too. How can we achieve that? We can dedicate one bit for sign. If this bit is 0 then we interpret other 7 bits as a positive number, otherwise as a negative number. It's best to use most significant bit for sign because it makes some operations easier. Trivial approach: Just read a number as-is: 00000001 == 1 and 10000001 == -1 01000010 == 66 and 11000010 == -66 01111111 == 127 and 11111111 == -127 Ones' complement: For any number x , negating its bin