In the table below, you'll see some decimal numbers in the left hand side. These are your targets. In the middle of the table, you see a row of black and red dots. These represent LED's. Red means binary 1. Black means binary 0. Go ahead and mash one of the dots. It changes state -- 0 becomes 1, 1 becomes 0. Notice that the rightmost number also changes. It is the decimal number corresponding to the binary number.
Your job is to set the binary bits so that the right column matches the left column.
Target | Your guess |
---|---|
43 | |
66 | |
100 | |
127 | |
-1 | |
-40 | |
-86 | |
-128 |
Now try out a couple of interesting 16-bit two-complement numbers.
Target | Your guess |
---|---|
1998 | |
-1998 |
Don't forget there is some binary arithmetic in
Assignment 1.
The middle rows of circle in the following figure
are two eight-bit numbers to add.
You press these to set the number.
The top row of squares is the carries
and the bottom row is the sum.
Now add 66 and -40.
Ask your lab instructor to verify that you've pushed all the right buttons.
Open a new C++ Source File in Lab02.cpp and type in the following outline of the main routine:
// Lab 2 -- CSCI 201.0L? // Your Name // #include <iostream.h> int main() { return 0 ; }
Even though this program does absolutely nothing, go ahead and Build it, just to make sure you've created the program, project, and workspace correctly.
At the beginning of your program, add declarations for two integer variables i and j and two float variables y and z.
Now add statements to read user-provided values for these variables. Be sure to prompt before reading each value. Here's some example code for setting i.
cout << "Enter integer value for i" << endl ; cin >> i ;
Finally, write statements to print the six expressions listed in the following table:
Expression Number | Expression |
---|---|
1 | Average of y and z |
2 | Average of i and j |
3 | The reminder when i is divided by j |
4 |
2 y + 4 j z |
5 |
y + z ------- y - z |
6 |
i -------- i + 1 |
cout << "Expression 1 is " << (y+z)/2 << endl ;
After you have thoroughly tested your code, ask your instructor to test it. If it passes the test, print your program and leave a copy with your lab instructor.