Advertisement
Guest User

boolean and bitwise operations

a guest
Apr 4th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. == boolean logic ==
  2.  
  3. definition rougly equates to logic involving things that can be one of two states (true or false, 1 or 0)
  4.  
  5.  
  6. == Basic boolean operations ==
  7.  
  8. === NOT ===
  9. negates a given input
  10.  
  11. Truth Table
  12. _______
  13. | I | O |
  14. |---|---|
  15. | 0 | 1 |
  16. |---|---|
  17. | 1 | 0 |
  18. |___|___|
  19.  
  20. The C language equivalent operator should be ! (not 100% sure).
  21.  
  22. === OR ===
  23. takes two inputs and outputs 1 if AT LEAST ONE input is 1, or 0 if neither is.
  24.  
  25. The OR bitwise operator can be used to force a sequence of bits into their on (1) state.
  26. In MIPS, you will occasionally see the OR instructiong being used to initialize a register to an immediate value.
  27.  
  28. The C language equivalent operator is |
  29.  
  30. Truth Table
  31. _____________
  32. | I1 | I2 | O |
  33. |----|----|---|
  34. | 0 | 0 | 0 |
  35. |----|----|---|
  36. | 1 | 0 | 1 |
  37. |----|----|---|
  38. | 0 | 1 | 1 |
  39. |----|----|---|
  40. | 1 | 1 | 1 |
  41. |____|____|___|
  42.  
  43.  
  44. === AND ===
  45. Takes two inputs and outputs 1 if BOTH inputs are 1, or 0 if neither is.
  46.  
  47. The AND bitwise operator can be used to capture a specific set of bits, ignoring the state of the rest.
  48.  
  49. The C language equivalent operator is &
  50.  
  51. Truth Table
  52. _____________
  53. | I1 | I2 | O |
  54. |----|----|---|
  55. | 0 | 0 | 0 |
  56. |----|----|---|
  57. | 1 | 0 | 0 |
  58. |----|----|---|
  59. | 0 | 1 | 0 |
  60. |----|----|---|
  61. | 1 | 1 | 1 |
  62. |____|____|___|
  63.  
  64. === XOR ===
  65. Takes two inputs and outputs 1 if the inputs do not match, or 0 if they match
  66.  
  67. The XOR bitwise operator can be used to flip the state of a bit or sequence of bits
  68.  
  69. The C language equivalent operator is ^
  70.  
  71.  
  72. Truth Table
  73. _____________
  74. | I1 | I2 | O |
  75. |----|----|---|
  76. | 0 | 0 | 0 |
  77. |----|----|---|
  78. | 1 | 0 | 1 |
  79. |----|----|---|
  80. | 0 | 1 | 1 |
  81. |----|----|---|
  82. | 1 | 1 | 0 |
  83. |____|____|___|
  84.  
  85.  
  86. == Bitwise Operations ==
  87.  
  88. Bitwise Operations perform multiple boolean operations within one instruction. This is done by comparing the bits
  89. on the same position. For example, consider the simple example of 0x05 OR 0x0C.
  90.  
  91. 5 = 0 1 0 1
  92. C = 1 1 0 0
  93.  
  94. we start by performing a boolean OR with the rightmost bits of the two numbers (1, 0), giving us an output of 1
  95.  
  96. ? = ? ? ? 1
  97.  
  98. Then we perform the same operation with the next columns as such:
  99.  
  100. ? = ? ? 0 1 (0, 0 is 0)
  101. ? = ? 1 0 1 (1, 1 is 1)
  102. E = 1 1 0 1 (0, 1 is 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement