---
# System prepended metadata

title: Introduction of Computer Science<br>Ch3 & Ch4
tags: [必修, Introduction of Computer Sciencce, NTNU, CSIE]

---

# Introduction of Computer Science<br>Ch3 & Ch4
NTNU 計算機概論

##### [Back to Note Overview](https://reurl.cc/XXeYaE)
##### [Back to Introduction of Computer Science](https://hackmd.io/@sophie8909/SyU5Uuyhr)

###### tags: `NTNU` `CSIE` `必修`  `Introduction of Computer Sciencce`
# Ch3.Data Storage
## 3-1 Intronduction
-  Memory cells are arranged by address
- MSB (most significant bit) 為最高有效位元 
- LSB (least significant bit) 為最低有效位元
    - 在電子學看到的MSB LSB就是它們[:arrow_right: ](https://hackmd.io/@sophie8909/r1E_6h2IS)
- 8bits = 1 byte

## 3-2 Storing Numbers
### Storing Integers
![](https://i.imgur.com/kNIP2v5.png)




| Integer Representation            | range                  |     |
| --------------------------------- | ---------------------- | --- |
| Unsigned representation           | 0~(2^n^-1)             |     |
| Sign-and-Magnitude representation | -(2^n-1^-1)~(2^n-1^-1) |     |
| One's Complement representation   | -(2^n-1^-1)~(2^n-1^-1) |     |
| Two's Complement representation   | -(2^n-1^)~(2^n-1^-1)   |     |

### Excess system
- A positive number, called the magic number(bias) , is added to each number to shift them uniformly to the non-negative side.
- magic number is normally 【2^m-1^】 or 【2^m-1^-1】
- m is the number of bits used to represent an integer
### Floating-Point Representation
#### IEEE 754 standards for floating-point numbers
#### Single Precision(單精度)
精度：十進位小數後6位
| Sign | Exponent | Mantissa | 
| ---- | -------- | -------- |
| 1    | 8        | 23       |

#### Double Precision(倍精度)
精度：十進位小數後15位
| Sign | Exponent | Mantissa | 
| ---- | -------- | -------- |
| 1    | 11       | 52       |
## 3-3 Storing Text


| Codes   |                                                    | bits                                     | Application         |
| ------- | -------------------------------------------------- | ---------------------------------------- | ------------------- |
| BCD     | Binary Coded Decimal                               | 4(compressed) <br>or <br>8（zoned） bits | Accounting software |
| EBCDIC  | Extended Binary Coded Decimal Interchange Code     |                                          |                     |
| ASCII-7 | American Standard Code for Information Interchange | 7 bits + <br>1 bit<br>(parity check)     |                     |
| ASCII-8 | American Standard Code for Information Interchange | 8 bits                                   |                     |
| Big-5   |                                                    | 16 bits                                  | Chinese characters  |
| Unicode |                                                    | 16 bits                                  |                     |
| ISO     |                                                    | 32 bits                                  |                     |

## 3-4 Storing Audio
Audio data are transformed to bit patterns through **sampling**, **quantization**, and **coding**.
## 3-5 Storing Images

### Bitmap


### vector

## 3-6 Storing Video



# Ch4. Operations on Data

## 4-1 Logical operations

logical operation on bits can be unary[^unary] (one input) or binary (two inputs)
<br>We interpret 0 as the value flase and 1 as the value true
### Applications：Mask
A mask is a bit pattern that is applied to a target bit pattern to achieve a specific result
#### NOT
invert its input
    
    Target    1 0 0 1 1 0 0 0 
    ------NOT-------------------
    Result    0 1 1 0 0 1 1 1
    

#### AND
using 0 Force to 0
    
    Target    1 0 0 1 1 0 0 0 
       AND    0 0 1 1 0 1 0 1 
          ----------------------
    Result    0 0 0 1 0 0 0 0 
    
#### OR
Using 1 Force to 1

    Target    1 0 0 1 1 0 0 0 
        OR    0 0 1 1 0 1 0 1 
          ----------------------
    Result    1 0 1 1 1 1 0 1 
    
#### XOR
Using 1 Flipping bits

    Target    1 0 1 0 0 1 1 0
       XOR    1 1 1 1 1 0 0 0
          ----------------------
    Result    0 1 0 1 1 1 1 0



[^unary]:unary 一元運算

## 4-2 Shift operations (這邊教授 **疑似** 標錯所以當作4-2)

### Logical shift operations

### Arithmetic shift operations(Rotate)
```c=
int main ()
{
    int a = 10, b = -a ;
    
    printf( "a = %d \n"
            "a >> 1 = %d, a >> 2 = %d\n"
            "a << 1 = %d, a << 2 = %d\n"
            "b = %d\n"
            "b >> 1 = %d, b >> 2 = %d\n"
            "b << 1 = %d, b << 2 = %d\n"
            , a ,
            a >> 1 , a >> 2 ,
            a << 1 , a << 2 ,
            b ,
            b >> 1 , b >> 2 ,
            b << 1 , b << 2
            );
    return 0 ;
}
```


{%hackmd @sophie8909/csabb %}