The normal way a number is defined, works here as well. There are "b" number of digits in a number system of base "b". Here, we just have to change the definition to: there are "|b|" number of digits in a number system of base "b". The definition works perfectly after that. Then, we can just use the following equation:
Using this we can thus generate the first few numbers (0, 1, 2, 3, 4, 5...) in negabinary: 0, 1, 110, 111, 100, 101... (Sequence A039724 on Online Encyclopedia of Integer Sequences (OEIS)) where 0 and 1 have usual face values.
How do we convert a number to this base then? Write the number down in binary first. Then, going from right to left, at every odd place (i.e. x1, x3, x5 ...), if the bit is one, propagate a carry to the next bit. Also, while moving from right to left, add all the carries.
For example:
To convert 15 to negabinary:
- Convert 15 to binary
- 15decimal=1111binary
- Propagate from right to left
- 1111
- 1111
- 1211
- 2011
- 2011
- 10011
- 10011
- 10011negabinary
- Done! (This is correct since 16-0+0-2+1 = 15)
Addition is kinda done the way conversion is done, except that carries are propagated (one bit extra to the left, since 2negabinary = 110).
We can similarly define the other operations as well.
Let's take this onto another level itself: how about a number system that takes care of complex numbers as well (as digit strings)? I leave that upto you to figure out and comment about.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.