Help on the nature of negative binary numbers.

Discussion in 'General Electronics Chat' started by jandcando, Mar 22, 2015.

  1. jandcando

    Thread Starter New Member

    Mar 22, 2015
    3
    0
    I'm working on building my second processor in Logisim. It is going to be a small 8 bit processor with 32 bytes of RAM, and I'm creating it just for the sake of the experience. I just wrapped my mind around negative binary numbers thanks to the negative binary numbers page on this site, and I need help on how they should be handled in my processor.

    I want to use 8 bit numbers, but it looks like I'll need another bit on the end to represent the negative weight bit, so does that mean my registers and ALU need to handle 9-bit numbers? What special adaptations will I need to make to my ALU to handle this?
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,790
    827
    I am going to assume your "word" size is 8 bits. Normally, signed numbers use one bit for the sign bit, and the remainder of the word size for the value. In your case, that leaves 7 bits for your numbers meaning you can represent numbers from -127 decimal to 127.
     
  3. jandcando

    Thread Starter New Member

    Mar 22, 2015
    3
    0
    Ok thanks! Knowing that I don't need to add some funky 9th bit is good to know. So if I wanted to output the resulted number to a hexadecimal display, I would knock off the leftmost bit and use that to display a negative sign if it was on (and invert the rest of the bits)?
     
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,790
    827
    Sounds about right. The details depend on which scheme you use for negative numbers (there are more than one)
     
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Could you say exactly what display you have in mind? Do you plan to show the decimal or hexadecimal equivalent value? Using a 7-segment display?

    Sorry but I fear you could be confusing things there.
     
  6. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    Typically, negative numbers are represented as "2's complement", not a simple bit inversion. This makes math easier.

    To compute the absolute value of a negative 2's complement number, invert the bits, then add 1.

    The same thing is done to a positive number to make a negative number.
     
  7. jandcando

    Thread Starter New Member

    Mar 22, 2015
    3
    0
    Logisim has a built in component that just displays the hexadecimal value of the 4 bit number you put into it. I put 2 of these together, and then added some logic for displaying a negative sign if the number was negative. It also alters the incoming bits accordingly to display correctly (invert and add 1.)

    I appreciate the help, but I already got all that from the page about negative binary numbers on this site. My ALU is pretty much done already, and I tested it extensively along with the display I set up and it works!
     
Loading...