HC1 computer systems
Computer systems: hardware, software, data, user
→ definition: a group of hardware components together with the software or programs that run on
the hardware
- complex data types are build on basic data types
- signals can have two easy-to-recognize and easy-to-transmit states: high and low
- All information on machines is internally represented by bits
→ A bit = a logical entity that has value 0 or 1
- data representation:
• external: understandable by user
• internal: understandable by machine
→ intermediate representation and translation
- all data is represented by bit vectors like 00101101011
- 2 aspects for data representation:
- functionality: encoding data to bit vectors (and back)
- performance: efficient encoding (low memory/silicon consumption & fast processing)
- base n: numbers can only use ‘0’ … ‘n-1’ digits
• trade-off between: length of representation and number of available “digits”
- counting in base n: when digits are finished, you add another digit
→ 0110 11 100 110 111 1000 1100 1110 1111 10000 11000 11100 11110 11111
, Logical NOT Operator:
• Purpose: It is used to negate a boolean expression.
• Behavior:
• If the operand is "True" (any non-zero value), NOT will return False (represented as
0x00).
• If the operand is "False" (zero), NOT will return True (represented as 0x01).
Bitwise ~ Operator:
• Purpose: It flips each bit of the operand (bitwise NOT).
• Behavior:
• Each 1 becomes 0, and each 0 becomes 1.
• For example, ~0x41 would flip the bits of 0x41 (which is 01000001 in binary) to get
10111110 (which is 0xBE in hexadecimal).
Logical AND and OR Operators:
• Logical AND:
• Returns the second operand if the first operand is "True" (non-zero); otherwise, it returns
the first operand.
• This is because of early termination: if the first operand is "False" (0), there's no need
to evaluate the second operand, as the result of and will always be "False" in such a
case.
• Logical OR:
• Returns the first operand if it's "True" (non-zero); otherwise, it returns the second
operand.
• This also uses early termination: if the first operand is "True", the result is "True", so
the second operand doesn't matter.
Bitwise & and | Operators:
• Bitwise & (AND):
• Compares each corresponding bit of the two operands.
• The result has a 1 bit where both bits in the operands are 1; otherwise, the result has a
0 bit.
• Bitwise | (OR):
• Compares each corresponding bit of the two operands.
• The result has a 1 bit where at least one of the bits in the operands is 1; otherwise, the
result has a 0 bit.
Left Shift (x << y)
• Shifts bits left by y positions.
• Example:
• 01100010 << 3 ➔ 00010000
Logical Right Shift (x >> y)
• Shifts bits right by y positions, filling with 0s on the left.
• Example:
• 01100010 >> 2 ➔ 00011000
• 10100010 >> 2 ➔ 00101000
Arithmetic Right Shift (x >> y)
• Shifts bits right by y positions, replicating the leftmost bit.
• Example:
• 01100010 >> 2 ➔ 00011000
• 10100010 >> 2 ➔ 11101000
Computer systems: hardware, software, data, user
→ definition: a group of hardware components together with the software or programs that run on
the hardware
- complex data types are build on basic data types
- signals can have two easy-to-recognize and easy-to-transmit states: high and low
- All information on machines is internally represented by bits
→ A bit = a logical entity that has value 0 or 1
- data representation:
• external: understandable by user
• internal: understandable by machine
→ intermediate representation and translation
- all data is represented by bit vectors like 00101101011
- 2 aspects for data representation:
- functionality: encoding data to bit vectors (and back)
- performance: efficient encoding (low memory/silicon consumption & fast processing)
- base n: numbers can only use ‘0’ … ‘n-1’ digits
• trade-off between: length of representation and number of available “digits”
- counting in base n: when digits are finished, you add another digit
→ 0110 11 100 110 111 1000 1100 1110 1111 10000 11000 11100 11110 11111
, Logical NOT Operator:
• Purpose: It is used to negate a boolean expression.
• Behavior:
• If the operand is "True" (any non-zero value), NOT will return False (represented as
0x00).
• If the operand is "False" (zero), NOT will return True (represented as 0x01).
Bitwise ~ Operator:
• Purpose: It flips each bit of the operand (bitwise NOT).
• Behavior:
• Each 1 becomes 0, and each 0 becomes 1.
• For example, ~0x41 would flip the bits of 0x41 (which is 01000001 in binary) to get
10111110 (which is 0xBE in hexadecimal).
Logical AND and OR Operators:
• Logical AND:
• Returns the second operand if the first operand is "True" (non-zero); otherwise, it returns
the first operand.
• This is because of early termination: if the first operand is "False" (0), there's no need
to evaluate the second operand, as the result of and will always be "False" in such a
case.
• Logical OR:
• Returns the first operand if it's "True" (non-zero); otherwise, it returns the second
operand.
• This also uses early termination: if the first operand is "True", the result is "True", so
the second operand doesn't matter.
Bitwise & and | Operators:
• Bitwise & (AND):
• Compares each corresponding bit of the two operands.
• The result has a 1 bit where both bits in the operands are 1; otherwise, the result has a
0 bit.
• Bitwise | (OR):
• Compares each corresponding bit of the two operands.
• The result has a 1 bit where at least one of the bits in the operands is 1; otherwise, the
result has a 0 bit.
Left Shift (x << y)
• Shifts bits left by y positions.
• Example:
• 01100010 << 3 ➔ 00010000
Logical Right Shift (x >> y)
• Shifts bits right by y positions, filling with 0s on the left.
• Example:
• 01100010 >> 2 ➔ 00011000
• 10100010 >> 2 ➔ 00101000
Arithmetic Right Shift (x >> y)
• Shifts bits right by y positions, replicating the leftmost bit.
• Example:
• 01100010 >> 2 ➔ 00011000
• 10100010 >> 2 ➔ 11101000