Lab 04 · T1 Course Exercises
On this page
1. Numerical representation
2.2 Base conversion

- Binary: Each additional bit is equivalent to increasing a power of two
- = 32 —> 0010 0000

- Hexadecimal: Binary is divided into groups of four digits
- 0010 | 0000 —> 0x20
- Shifting the hexadecimal system one bit to the left is equivalent to multiplying by 16, which means moving the binary system 4 bits to the left.
- eg: = 4096 = 0x1000
2.3 Base conversion

2.1 big-endian / little-endian

- Big-endian: The most significant bytes are placed at lower memory addresses.
- Little-endian (little endian): The least significant byte is placed at the lower memory address.
- It can also be written as: big-endian order is positive
Note⚠️: D: The hexadecimal should be divided from right to left. If it is not enough, add 0
2.17 Signed integers and two’s complement numbers
- complement a 2 : MSB weight from + becomes - (8bit is -128)

- Sign extension (Sign extension) is to copy the original highest bit.
- The highest bit of a positive number is
0, fill left0. - The highest bit of a negative number is
1, fill left1.
- The highest bit of a positive number is

2. Floating point numbers
Representation of floating point numbers:
- Signe + exponent + mantissa (32bits en total)
- bias = + 1 ----- 32bits : 8 bits for exponent, k = 8
- Steps: Take -46.0 as an example
-
- The sign is +/-, -: 1
-
- Convert to binary, 46 = 32+8+4+2 —> 0010 1110
-
- standardization, = *
-
- Calculate component, E = 5 + 127 = 132 =
-
- Save the mantissa (the leading 1 is not saved), 0111 000000…(23bits)
-
- 1|100 0010 0|011 1000 0000 0000 0000 0000 C 2 3 8 0 0 0 0 -46.0 = 0xc2380000
-
- big / small endian

- big / small endian
-
3. Binary arithmetic
Arithmetic rules
- shift shift
- Shifting one position to the left is equivalent to multiplying by 2
- Shifting one position to the right is equivalent to dividing by 2
- ⚠️Note that left shift may lose the highest bit, and the signed uniqueness of negative numbers does not apply.
- 178 - 89 = 89:
-
10110010 - -01011001
-
01011001
-
carry and overflow
-
‼️new notes:
- OF indicates whether to overflow if signed
- CF indicates whether a carry occurred (also means, whether an unsigned overflow occurred)
- So when doing the problem, first calculate the binary system to see if there is a carry (CF), and then press the signed case to see if there is a signed overflow (OF).
-
carry
- I only care about whether te el rossec de sortida, so press unsigne!!
- 10110010 = 178
-
- 01011001 = 89
- 1 00001011 = 267 (9bits required for correct representation)
- ⬆️The 1 here is carry (if we only have 8bits, then carry 1 is generated)
- Note ⚠️ does not mean overflow occurs, you need to see if there is a symbol!
- Unsigned, 1 0000 1011 is 267, exceeds 255, unsigned overflow✅ (CF = 1, OF=0)
- There is a sign, the original title is: 10110010 (-78) + 01011001 (89) = 11, within -128 ~ 127, overflow🈚️ (OF = 0)
- ! ! ! Pay attention to the difference (OF/CF are just symbols and do not mean “overflow” in the mathematical sense)
- When judging CF, check whether the highest bit is carried out; when judging OF, check whether the signed result is out of range.
-
overflow
- The mathematically correct result cannot be expressed using the currently specified number of signed bits.
- You can convert it into a symbolic number and then see if the range exceeds
-
Català: The flag carries the indica and the ròssec de sortida, the flag becomes the overflow indica and the result is the correct representation of the sign.
-
Español: El flag de carry indica el acarreo de salida, mientras que el flag de overflow indica que el resultado no se puede representar correctamente con signo.
4. Logical operations
- Operation symbols
- ~ NOT, negate
- & AND, two 1’s
- |OR, at least one 1
- ^ XOR, two different bits
- ! logical NOT, a = 01010101 — > !a = 00000000, a = 00000000 —> !a = 00000001
- && logical AND, both are non-zero
- || logical OR, at least one non-zero value


Machine-assisted translation · Read Chinese original
