Negative Base Numbering Systems

math 0 comments suggest edit

UPDATE: I updated the article a bit to better explain decimal expansion to negabinary

Ok, here is where I go and really geek out a bit. Scott presents a simple javascript to display negative numbers as red. He takes a nice clean straightforward approach by using javascript to inject a CSS class on specific elements that have a negative number.

As his script merrily iterates its way through the page’s elements, it checks the values of the element to see if the first character is a “-” (dash). And this works just fine for the majority of you people so thoroughly stuck on the “decimal” system.

But as I pointed out in his comments, this discriminates against negative base numbering systems such as …drumroll… Negabinary!

Doesn’t negabinary sound like one in a long string of major villains to attack Godzilla and end up destroying Tokyo yet again?

Negabinary is a lot like binary’s evil twin. Rather than a base 2 system, negabinary is base -2. The beauty of negabinary is that there is no need for a negative sign (aka the sign bit). All integers, negative or positive, can be written as an unsigned stream of 1s and 0s.

To expand a decimal number into negabinary, you simply divide the number by -2 repeatedly. Each time you divide the number, you record the non-negative remainder of 0 or 1. Afterwards, you take those remainders in reverse order and there you have it, the negabinary expansion. Simple no?

Keep in mind that we are doing remainder division here. So -1/-2 is not one half, but 1 remainder 1. Likewise, 1/-2 is 0 remainder 1.

Huh?

Keep in mind this simple algerbraic formula: if a / b = c remainder d, then bc + d = a.

Thus, to expand decimal 2 in negabinary:

 2 / -2 = -1 remainder 0
-1 / -2 =  1 remainder 1
 1 / -2 =  0 remainder 1

Taking those remainders in reverse order we get 110. So 110 is the negabinary representation of decimal 2.

I remember learning that there were computing systems built (perhaps experimental) that used negabinary instead of binary. Apparently there are benefits to representing a number without a signed bit. Unfortunately, like a good evil twin, negabinary makes arithmetic operations quite complicated.

I was going to write up a whole exposé on negabinary, but the Wikipedia did a much better job than I would have. My memory of my college math lectures on alternate numbering system is pretty hazy. Throughout history, humans have tried out various numbering systems other than base 10. The Mayans used some sort of hybrid of base 20 and base 360. I kid you not.

So with a small alteration, we can adjust Scott’s script to accomodate negabinary enthusiasts.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

9 responses

  1. Avatar for David
    David May 1st, 2006

    One of my CS teachers in college would tell us his favorite numbering system was base -3... would that be Negatrinary???

  2. Avatar for Haacked
    Haacked June 20th, 2007

    In case you're wondering, the algorithm described leaves out this important note:
    Note that if a / b = c, remainder d, then bc + d = a. For example, to expand 2
    2 / -2 = -1 remainder 0
    -1 / -2 = 1 remainder 1
    1 / -2 = 0 remainder 1
    Thus 2 = 110 in negabinary.

  3. Avatar for Daniel Watkins
    Daniel Watkins June 20th, 2007

    David: Negaternary, I'd have thought.

  4. Avatar for Shaik Moulaali
    Shaik Moulaali December 13th, 2007

    interesting..unlike traditional binary numbers, negbinary can represent both positive and negative numbers with out using
    sign bit. now tell me what is the maximum and minimum number
    that can be represented using negbinary number of 8 bits ? ;)

  5. Avatar for Ron
    Ron March 31st, 2009

    How about Negatory?

  6. Avatar for ...
    ... December 16th, 2010

    i don't understand it , what do you mean?

  7. Avatar for Ari
    Ari January 18th, 2011

    how to convert from decimal with fraction value to negabinary?
    example 25.25 and 2.75, how do we convert the fractioned values? please email the explanation da001kage@gmail.com
    thanks for explaining.

  8. Avatar for John Williams
    John Williams May 9th, 2012

    I'm just trying to teach myself C++ from Sams teach yoursel in 21 days, third edition bought it new but ran into a Now I know was a very simple problem and put it away for years now I have another issue and refuse to quit. There is a paragraph in the book that I don't know how to type because I can't make the small characters that mean to the power of but here is one I can cut and paste....
    As you know, the decimal system uses the digits 0-9 to represent numbers. If we wanted to put a larger number in column 10^n (e.g., 10), we would have to multiply 10*10^n, which would give 10^(n+1), and be carried a column to the left. For example, putting ten in the 10^0 column is impossible, so we put a 1 in the 10^1 column, and a 0 in the 10^0 column, thus using two columns. Twelve would be 12*10^0, or 10^0(10+2), or 10^1+2*10^0, which also uses an additional column to the left (12). Now my issue WHAT does the small n mean I can't find it anywhere and feel like I have to know to move on. Please help if you will. Thank You to 10th power.

  9. Avatar for Irene Kaminkowa
    Irene Kaminkowa August 3rd, 2016

    In the text
    So -1/-2 is not one half, but 0 remainder 1. Likewise, 1/-2 is 1 remainder 1.

    In the example
    2 / -2 = -1 remainder 0
    -1 / -2 = 1 remainder 1
    1 / -2 = 0 remainder 1

    Thus -1/-2 is 0 with remainder 1 in the text, and 1 with reminder 1 in the example
    The same sh... problem with 1/-2

    The scheme fails.

    The right approach: http://allproblems.ucoz.ru/...