# 2024-03-13

## Introduction

> **Summary**

> **keywords**

> **TODO**

> **HW**

> **Exercise**\*

> **Next time**

***

## Arithmetic w/ Unsigned Numbers

### Addition

* add bit-wise.
* if there's carry-out, you add 1 to the next digit.

### Subtraction

* borrow values from bigger digits, and subtract.
* This is so complex. Just use signed number arithmetic and convert back.

### Multiplication

* add each multiplication to each digit.
* Just like we learned in elementary school.

## Arithmetic w/ Signed Numbers

### Addition

* The system is well defined, so you just need to calculate bit-wise.

### Problems

* When (positive)+(negative) makes additional digit carry out, you discard it.
* When (positive) +(positive) makes additional digit carry out, it is an overflow.
* When (negative) + (negative) makes sign digit into positive, it is an underflow.
* In either way, overflowed number can't be represented in bit limitation.

### How do you handle overflow/underflow?

* This problem also easily happens in multiplications.
* How to handle? just use additional 1 bit more for error catching.

(ONLY FOR 2's complement) Sign extension might handle it.

* the sign-bit should be replicated for n more digits in front.

### Subtraction

* take the 2's complement of the subtrahend(latter value) and add it.
* discard any final carry bit.

## Binary Codes & its arithemetics

> It is not defined mathematically.

* It is just a set of numerical information.
* It's a pattern of numerical representation of another element of information.
* Packed representation is bit-inefficient.

### Addition

THOUGH it is not defined mathematically, it mimicks a sequence of natural numbers.\
So a psudo-addition is possible.

If the sum is smaller than 10, the result is correct.\
If the sum is bigger than 9, since we don't use 10\~15 reprentations, we need to skip 6 representation and get the next representation. That is numerically equivalent to "adding 0110" more.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://2ood.gitbook.io/2ood-knowledge-base/lecture-notes/digital_design/2024-03-13.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
