Objectives
- Apply knowledge of C# Controls to a project scenario.
- Apply knowledge of visibility properties of C# Controls.
- Apply knowledge of the logical operators AND and OR.
- Learn to calculate the decimal (base 10) value of an 8-bit binary (base 2) number.
- Learn to Logical AND and Logical OR two 8-bit binary numbers to enhance cognitive thinking skills.
- Learn to bitwise AND and bitwise OR two 8-bit binary numbers to enhance cognitive thinking skills.
- Demonstrate calculation of hexidecimal (base 16) numbers from decimal (base 10) values.
- Demonstrate ability to generate colors from binary numbers.
Background
Binary numbers are made up of 0 and 1. An example of a binary number would look like: 10010111
This is an example of an 8-bit binary number. A 16-bit binary number would look like: 1001001011011001
This project deals with 8-bit binary numbers. The decimal value of 10010111 is not 10,010,111. It is actually 151 as a base 10 numeric value.
How is it calculated?
Binary numbers count from right to left. Each digit to the left is twice the value of its digit to the right. A graphical representation of this would look like this:
Hence, a 1 in the 128 box gives the binary number a decimal value of at least 128.
Some Examples:
Binary Number |
|
Decimal Value |
10000000 |
= |
128 |
10000001 |
= |
129 |
00000000 |
= |
0 |
00000001 |
= |
1 |
00000010 |
= |
2 |
00000011 |
= |
3 |
00000100 |
= |
4 |
00000101 |
= |
5 |
11111111 |
= |
255 |
Thus, 0 to 255 offers 256 values within an 8-bit binary number.
Bitwise AND (&)
How to bitwise AND binary values together:
10010010 |
& |
01101101 |
= |
00000000 |
10010010 |
& |
01111101 |
= |
00010000 |
01010101 |
& |
01010101 |
= |
01010101 |
Bitwise AND requires two operands, just like a logical AND. Bitwise AND is represented by a single ampersand, &, whereas a logical and is represented by a double ampersand, &&. How does it work? Use a logical AND to compare each of the bits against each other, starting from the right.
10101010 |
11001100 |
|
_______0 |
Only when both numbers are a 1, will the result be a 1. Otherwise, the result is 0.
10101010 |
11001100 |
|
____1000 |
and so on...
Bitwise OR ( | )
How to bitwise OR binary values together:
10010010 |
| |
01101101 |
= |
11111111 |
10010010 |
| |
01010000 |
= |
11010010 |
01010101 |
| |
00000111 |
= |
01010111 |
Bitwise OR is represented by a single | (pipe) whereas a logical OR is represented by a double pipe, ||. How does it work? Use a logical OR to compare each of the bits against each other, starting from the right.
10010010 |
01101101 |
|
_______1 |
When either bit or both bits are a 1, then the result is a 1.
10010010 |
01010000 |
|
___10010 |
Bitwise XOR (^)
There is another bitwise operator, XOR, which is an abbreviation for eXclusive OR. XOR works like this: When either bit is a 1, then the result is a 1, but if both bits are a 1 or if both bits are a 0, then the result is a 0.
10010010 |
01010000 |
|
11000010 |
Hexadecimal numbers
Another popular conversion in CGT is converting decimal numbers to hexadecimal (base-16) numbers. Below is a table that demonstrates how the numbers map to one another:
Decimal |
Hexadecimal |
0 |
0 |
1 |
1 |
2 |
2 |
3 |
3 |
4 |
4 |
5 |
5 |
6 |
6 |
7 |
7 |
8 |
8 |
9 |
9 |
10 |
A |
11 |
B |
12 |
C |
13 |
D |
14 |
E |
15 |
F |
Converting Decimal Numbers to Hexadecimal
Given the decimal values:
Red (R): 128
Green (G): 210
Blue (B): 78
R: 128 / 16 = 8 R0 => 80
G: 210 / 16 = 13 R2 => D2
B: 78 / 16 = 4 R14 => 4E
Resulting Hex value is: 80D24E
Converting Hexadecimal Numbers to Decimal
Given the Hex value: 80D24E
R: 80 => 8 R0 => 8*16+0 = 128
G: D2 => 13 R2 => 13*16+2 = 210
B: 4E => 4 R14 => 4*16+14 = 78
Resulting RGB value is: (128, 210, 78)
Procedures
Create an project of this general form:
However:
Initially, only one select box and the text fields and will be visible in each Color Row to the user. The color box should start off as grey (#cccccc) for visibility, but upon the first change, it will default to all "0" if the hex number has not been calculated. See below.
And once a value is chosen, the decimal value is calculated, the Hex value is calculated, and the values are stored in the result boxes to the right. Also, the next select box will then appear and the selection box that was just changed will appear disabled such that the value cannot be changed. (only one row shown here for simplicity)
And the process repeats from there, thus the next selection would look like:
After the eighth and final bit value is chosen, again, the decimal value of the 8-bit number would be calculated and stored, and you can begin the next row. You should be able to begin any row at any time. They do not have to be completed in order from top to bottom.
Upon choosing the eighth and final bit of the third 8-bit number, again, the decimal value of the 8-bit number would be calculated and stored, and a final row of the table would appear. This final row will contain the bitwise selection boxes allowing you to choose two 8-bit numbers.
At this point, you would then choose whether to bitwise AND (&) or to bitwise OR ( | ) or to bitwise XOR ( ^ ) these two 8-bit numbers together. Upon changing any of those 3 select boxes, the result would be recalculated.
Turn In
- Version 1: Project as described above.
Above & Beyond
- Version 2: Allow the user to update any bit at any time. In other words, display all bits at startup and do not disable each bit once a number is chosen. Allow that number to be changed and recalculate everything upon its change.
Examples
Finalization
- Test your project
- Finalization
(do this for both applications)
- Build > Configuration Manager
- Change "Active solution configuration" to Release.
- Make sure "Configuration" changes to Release.
- Close
- Rebuild
- Look in <project folder> / bin / Release
- Double click <projectName>.exe
- On your own
- Write the pseudocode for each application in a large comment block at top of the .cs files. Be thorough with your pseudocode. It should be easily readable by anybody (regular english terminology). Essentially, if there's a line of code, there should be a line of pseudocode. You do not have to write pseudocode for the "layout" code.
- Turn in both entire projects.
Grading
If the project is not functional (does not work), then your project grade starts at 50%. This is a professional project; our company will not accept partial work. Late work will not be accepted. (In the real world, you would not get paid for a project you did not complete. In our world, you start at 50%)
- 20% Aesthetics & Usability
- (Professional, effective and easy navigation, common scheme across
entire site, use of images, originality, creativity, usability features, intuitive, user friendly, easy to use, etc. -- More than just form elements -- CSS, look 'n' feel, etc.)
- 55% Coding, Logic, & Functionality
- (Does not crash, proper indentation, neatness, free from errors, correct logic, security, follows typical coding standards, apparent planning, etc.)
- 15% Commenting
- (In general, one line of comment per line of code)
- 10% Above & Beyond
- The minimum requirements for an A on a perfect project are completion of versions 1 and 2. Version 3 must be completed in order to achieve 100% on a perfect project.
|