Two's Complement Arithmetic

Two's Complement Arithmetic

Download...

I wrote a utility to help me double check my homework for a class in MIPS assembly.

Remember kids, always double check your work. If you're a programmer, be sure to use your special powers of laziness and write some code to do all your checking for you...

Note: This code helped me find a typo in my instructor's paper on two's complement arithmetic! For more information, I suggest reading the wikipedia article .


This is ANSI standard C++ code. I haven't bothered testing it anywhere but on my lil' old linux boxen. You need boost installed to compile and run this.

With gcc, it's trivial:

g++ sef.cpp -o sef

Run it:

./sef <width of fractional bits> <floating point> <floating point>

tim@raven ~/sef $ ./sef 16 1.234 4.56
1.234 =
+-+---------+---------------------+
|0|0111 1111|(1)001 1101 1111 0011|
+-+---------+---------------------+

24 bit Two's Complement:
0000 0000 1001 1101 1111 0011

4.56 =
+-+---------+---------------------+
|0|1000 0001|(1)001 0001 1110 1011|
+-+---------+---------------------+

24 bit Two's Complement:
0000 0000 1001 0001 1110 1011

sum =
+-+---------+---------------------+
|0|0111 1001|(1)011 1001 0110 0111|
+-+---------+---------------------+

Popular Tags

Archives