Contemplation of my learning. : 2's complement - The way computer counts.
2's complement - The way computer counts.
Let's start first post with counting. Computers understand binary language which consists of only two symbols, basically represented as '0' and '1'. I assume you know how to represent decimal numbers into binary domain. I'm giving here a fictional story to make you understand how computer counts.
In binary world there are two persons, Jedi and Vader. Jedi stands for good and Vader is of evil. Jedi rules over '+'(positive) domain and Vader rules over '-'(negative) domain. Now both have to count but they are opposite to each other so they start with exact opposite ends(as they don't like each other). Jedi start with all 'zero' bits while counting in his positive domain and Vader start with all 'one' bits his domain. They have something in common(both are powerful) and that's why the pattern in which they counts is same but they use just opposite symbols. What is '0' to Jedi is '1' to Vader and vice versa. Below two lists are given. The numbers in list are of 4-bits(1 bit for sign, 3 bits for value) for demo. Entries in list are written as "s vvv". Here 's' is sign bit and 'v' is the data bit. Space between sign bit and data bits is just for sake of clarity. It has no other meaning. Left list is for Jedi and right list is for Vader. While counting, sign bit is always '0' for Jedi and '1' for Vader. As you can see the bit pattern is exactly same for these lists, except that they are opposite to each other in bit. Number in parentheses is the corresponding value of that bit pattern.
In binary world there are two persons, Jedi and Vader. Jedi stands for good and Vader is of evil. Jedi rules over '+'(positive) domain and Vader rules over '-'(negative) domain. Now both have to count but they are opposite to each other so they start with exact opposite ends(as they don't like each other). Jedi start with all 'zero' bits while counting in his positive domain and Vader start with all 'one' bits his domain. They have something in common(both are powerful) and that's why the pattern in which they counts is same but they use just opposite symbols. What is '0' to Jedi is '1' to Vader and vice versa. Below two lists are given. The numbers in list are of 4-bits(1 bit for sign, 3 bits for value) for demo. Entries in list are written as "s vvv". Here 's' is sign bit and 'v' is the data bit. Space between sign bit and data bits is just for sake of clarity. It has no other meaning. Left list is for Jedi and right list is for Vader. While counting, sign bit is always '0' for Jedi and '1' for Vader. As you can see the bit pattern is exactly same for these lists, except that they are opposite to each other in bit. Number in parentheses is the corresponding value of that bit pattern.
Read full article from Contemplation of my learning. : 2's complement - The way computer counts.
No comments:
Post a Comment