Slot03 04 BasicComputation
Slot03 04 BasicComputation
• Computer program
A set of instructions that computer hardware will execute
• Issues for a program/software
Usability, Correctness, Maintainability, Portability
• Computer software
A set of related programs
• Steps to develop a software
Requirement collecting, Analysis, Design, Implementing, Testing, Deploying, Maintaining
• Data
Specific values that describe something
• Information
Mean of data
• Fundamental Data Units
Bit, Nibble, Byte, KB, MB, GB, TB
• Data Representation
Number systems: 2, 10, 8, 16
• Program Instructions
<opcode, operand1, operand 2>
• Programming Languages
Machine language, Assembly, High-level languages
[PFC] Basic Computation 1
Basic Computation
7 Understand precedence
8 Understand casting
c:6356751 'A'
i:6356744 1
l:6356740 1000
• The operator & will get the address of a variable or code.
• The operator sizeof(var/type) return the size (number f:6356736 0.5
of byte) occupied by a variable/type
d:6356728 12.809
[PFC] Basic Computation 8
Do Yourself Now
Modify
Change \ to \\ then run it
RUN &
RUN
Error
Keyboard is 3
a character
device Conversion rules are pre-defined in C
RUN &
RUN
Error
>> Right shift operator makes the sign bits of the operand is
preserved (operands unchanged) How many byte (bits)
~ Inverse bits of the operand does operand occupy?
n=12: 0000 0000 0000 1100 n&m
m= 8: 0000 0000 0000 1000 0000 0000 0000 1100
k=–1: 1111 1111 1111 1111 0000 0000 0000 1000
0000 0000 0000 1000 →
→88
n|m
0000 0000 0000 1100
0000 0000 0000 1000
12
→ 12
0000 0000 0000 1100 →
n^m
0000 0000 0000 1100
0000 0000 0000 1000
→4
0000 0000 0000 0100 → 4
[PFC] Basic Computation 54
Bitwise Operators
Operator Relational Operators Action
>> Right shift operator makes the sign bits of the operand is
preserved (operands unchanged) How many byte (bits)
~ Inverse bits of the operand does operand occupy?
n=12: 0000 0000 0000 1100 n << 1 0
m= 8: 0000 0000 0000 1000 0000 0000 0000 1100 → 24
k=–1: 1111 1111 1111 1111
n << 2 00
0000 0000 0000 1100 → 48
0
0000 0000 0000 1100 → 6
n >> 1
11
1111 1111 1111 1111 → -1
k >> 2
[PFC] Basic Computation 55
Bitwise Operators
Operator Relational Operators Action
>> Right shift operator makes the sign bits of the operand is
preserved (operands unchanged) How many byte (bits)
~ Inverse bits of the operand does operand occupy?
n=12: 0000 0000 0000 1100
~t
m= 8: 0000 0000 0000 1000
0000 0000 0000 0010
k=–1: 1111 1111 1111 1111
1111 1111 1111 1101 → -3
0000 0000 0000 0011 → 3
int n = 3; chart
long t = 123;
short
double x = 5.3;
int
3*n + 620*t – 3*x
(int*int)+(int*long)-(int*double) long