User Tools

Site Tools


notes:c4eng:fall2023:projects:stl1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:c4eng:fall2023:projects:stl1 [2023/09/28 00:26] – [USING BINARY] lbond1notes:c4eng:fall2023:projects:stl1 [2023/09/28 02:57] (current) – [BITWISE EXCLUSIVE OR] mwinter4
Line 15: Line 15:
  
 ====USING BINARY==== ====USING BINARY====
-To show that a number is in binary use 0b before it. For example: 0b0000 would represent 0 in binary and 0b1111 would be equivalent to 15 in the decimal system. Otherwise, 1111 may be confused for 1,111 in decimal. This project can be done in decimal, but it may make it easier to use decimal, because 0b0010 definitely requires the twos place LED to light up, since the LEDs are counting in decimal.+To show that a number is in binaryuse 0b before it. For example: 0b0000 would represent 0 in binary and 0b1111 would be equivalent to 15 in the decimal system. Otherwise, 1111 may be confused for 1,111 in decimal. This project can be done in decimal, but it may make it easier to use decimal, because 0b0010 definitely requires the twos place LED to light up, since the LEDs are counting in binary.
 ====LIGHT PATTERN==== ====LIGHT PATTERN====
  
Line 45: Line 45:
  
 ====BITWISE INCLUSIVE OR==== ====BITWISE INCLUSIVE OR====
 +The bitwise inclusive OR, is represented in C with a vertical bar symbol (often referred to as a pipe): <wrap hi>|</wrap>
  
 +This operator compares the values of some operands in binary and yields a string of bits that contains all the bits of each operand (OR operation). 
 +
 +Example: 
 +**01100011 | 00011001**
 +yields **01111011**
 +
 +Similarly, you can perform this operation in any base, including decimal: 
 +**10 | 4**
 +is equal to **7** because <code> 00001010 | 00000100 == 00001110 </code>
 ====BITWISE EXCLUSIVE OR==== ====BITWISE EXCLUSIVE OR====
 +Exclusive OR, typically referred to as XOR, is denoted by the ^ operator in C. 
  
 +XOR compares some operands in binary, and for each bit compared yields 1 if and only if the bits of each operand have one and only one 1 between them. 
 +
 +Example: 
 +<code>1011 ^ 1101 == 0110</code>
 +
 +This of course can be done with integers of any base, like so: 
 +<code>3 ^ 7 == 4</code>
 +
 +Which would be interpreted in binary as:
 +<code>0011 ^ 0111 == 0100</code> 
 +
 +XOR is an important operation that, when combined with AND, can do operations such as binary addition. 
 ====BITWISE NOT==== ====BITWISE NOT====
 +The bitwise NOT operation, represented with the operator <wrap hi>~</wrap>, can be thought of simply as an inverter. That is, it takes some operand and inverts each bit. 
 +
 +Example: 
 +<code> ~0011 == 1100 </code> 
  
 +This can be done for different bases as well: 
 +<code> ~5 == 10 </code>
 +Because **5** is represented in binary as **0101**, inverting the bits results in binary **1010**, i.e. decimal **10**.
 =====SELECTION STRUCTURES: IF===== =====SELECTION STRUCTURES: IF=====
 For this project, we will mainly be using the **if** and **else** functions. An **IF** statement tells the computer that when the condition specified by the statement is met, then to do the command string later specified. When the condition specified by the statement is not met, it will completely skip the function and continue on its journey to make you frustrated. BUT, we can add an **else** command to tell the computer to do a task or command string when the condition isn't met. For this project, we will mainly be using the **if** and **else** functions. An **IF** statement tells the computer that when the condition specified by the statement is met, then to do the command string later specified. When the condition specified by the statement is not met, it will completely skip the function and continue on its journey to make you frustrated. BUT, we can add an **else** command to tell the computer to do a task or command string when the condition isn't met.
notes/c4eng/fall2023/projects/stl1.1695860775.txt.gz · Last modified: 2023/09/28 00:26 by lbond1