Thursday, October 7, 2010

Values, Types and Representation (Decimal number system) - I

During my childhood my grandfather used to say me with a lot of pride "Ancient Indians invented Zero which is the cause for all the great revolution that led us to this Modern world". I never liked this idea, it is bullshit! I mean how could '0' be an invention??? It is just a bloody letter! I could've used 's' to represent zero, or anything of my choice! But then later when I came to know about the numbering system used to represent count prior to invention of '0', I understood what an important invention it is (not as a symbol but as a concept)! Think about Roman numerals, which never had a zero in it so how do they represent 10 with introduction of a new letter 'X', they used new symbols to represent higher values "I,V,X,L,C,D,M". This kind of representation makes life very hard when it comes to doing math (VI + IV = X [oh god!]) or representing a huge number (I always wonder how would they represent a billion :D). Then came the revolutionary idea of positional decimal number system (Hindu–Arabic numeral system) with the greatest invention of science Mr. Zero. Just follow this link to wikipedia article!

Positional representation of numbers are fairly simple you'll have a collection of unique symbols to represent count of 0 to N, having a total of N+1 symbols. This N+1 is the "base" for your numbering system. From now on I will use the term 'digit' to denote the unique symbol that represents a basic count (0,1,2,3,4,5,6,7,8 and 9 in a decimal system). Then use the combination of these symbols to represent any arbitrary count/value, in this combination the digit changes its value based on its position. Say, in number 548, 5 represents "five hundred" and not just "five", 4 represents "forty" and not just "four" and finally 8 represents the "eight" hence the count it represents is "five hundred and forty eight".

Let us try to understand the basics of decimal numbering system. We all know deci is 10 raised to the power of 1 i.e., 10. "Decimal number system" is called so because it has 10 (deci) unique symbols (digits) in it (0 - 9) to represent the count from zero to nine. A value of the digit is calculated by the "position" and the value it represents say for example if digit 9 is in (starting from position 0) 3rd position of a number then it is not "Nine" rather is is "Nine thousand"! i.e., 9 multiplied with ("base" raised to the power of "position"). With this number system we can represent any arbitrary value with just ten digits. Now we will see what is so special about zero, zero is used for one important purpose i.e., to give shift in position of all non-zero digits that precedes them, without adding a value! That means when 0 is not preceded by any non-zero digits, then that 0 really adds no value to the count, example 00009230 is the same as 9230, where the 0 that succeeds gives a shift of 1 position to the digits 3, 2 and 9, thus making 9 as "nine thousand", 2 as "two hundred" and 3 as "thirty" without altering the value. Preceding numbers with zero will help us in "fixed width" numbers.

Sometimes you would have come across fixed width numbers, say for example when filling in the postal code in your post card (the one in the picture has 6 boxes for postal code at the bottom of the address area). Fixed width numbers are always represented with fixed number of digits (6 digits in the post card shown in the picture below). If my postal code is "Five hundred and eighty seven" I cannot simply write 5, 8 and 7 as I have 6 boxes to fill, so I must write 0, 0, 0, 5, 8, 7, thus filling all the boxes without damaging the value. With fixed width number we also come across two interesting properties the maximum and minimum representation. With six boxes the minimum code one could use would be 0, 0, 0, 0, 0, 0 and the maximum number could be 9, 9, 9, 9, 9, 9 (Anything above this number cannot be fit in).

Typically the minimum value of any "fixed width" number be 0 and the maximum will be (base raised to the power of width - 1). That means, fixed width numbers could represent N unique values from "minimum" to "maximum" where N will be (base raised to the power of width). For example if my width is 2 and base is 10 then I can represent 100 unique values from 00,01,02, ... to 99.
(to be continued ...)

No comments: