Overview
This note page goes over a collection of different low-level computing concepts. They appear in no particular order and mostly exist here because they have nowhere else to exist.
Data Types
While all data in a computer is stored as a logical #Bit, a collection of bits can be encoded in a specific way to represent a few basic data types. These are a few primitve data types, or the most basic of data types and their properties.
Data type | Size | Range |
---|---|---|
char | 1 Byte | [-128,+127] |
unsigned char | 1 Byte | [0, 255] |
short int | 2 Bytes | [-32768,+32767] |
unsigned short int | 2 Bytes | [0, 65535] |
int | 2 or 4 Bytes | [ |
long int | 4 or 8 Bytes | [ |
long long int | 8 Bytes | [ |
float | 4 Bytes | [3.4E-38, 3.4E+38] |
double | 8 Bytes | [1.7E-308, 1.7E+308] |
long double | 10 Bytes | [3.4E-4932, 3.4E+4932] |
Numbers
Numbers can be represented in a few different ways in computers. While most people are used to the decimal numbering system, computers use a variety of different positional based numbering systems for efficiency.
Positional System | Base | Allowed Digits |
---|---|---|
Binary | 2 | 0,1 |
Octal | 8 | 0-7 |
Decimal | 10 | 0-9 |
Hex | 16 | 0-9, A-F (A=10 ... F=15) |
In the positional numbering system values are determined by a base, positional index, and digit. To convert from an alternate number system to decimal you take sum of the base to the power of the positional index times the digit (
e.g. 1125 in base 8 converts to 597 in decimal
Fractional Numbers
There are two types of fractional numbers floats and doubles. doubles provide more bits for more accuracy.
Floats
Add info about how floating points are stored.
The IEEE 754 floating point number is a standard for representing a float.
- 32 bits (4 Bytes)
- 1 sign bit, 8 bits of exponent, and 23 bits of fractional number
- 6 decimal digits of precision
Doubles
The double provides more bits than the float for more accuracy.
- 64 bits (8 Bytes)
- 1 sign bit, 11 bits of exponent, and 52 bits of fractional number
- 15-17 decimal bits of precision
Signed Numbers
Number systems have to take into account that negative numbers have to be represented in some way. There are a few different methods to representing numbers as positive or negative (aka. signed).
Sign Magnitude
This simply reserves the first bit of a number to represent its sign. While its a simple solution it has a few issues.
- ambiguous zero - zero can be represented as +0 or -0
- arithmetic sign errors
- e.g.: -2 + 1 = 110 + 001 = 111 = -3?
Two's Compliment
This implementation removes the issue of ambiguous zero and makes arithmetic much easier. Similar to #Signed Numbers two's compliment uses the first bit as a sign indicator but instead uses an alternate system to represent negative numbers.
The two's compliment of a number can be obtained using the following steps:
- Inverting the bits
- Adding 1 to the result
e.g 28 in binary is 00011100
11100011 <- Inverted
11100100 <- Add one
Addition can be performed as usual, however to subtract we would negate the right operand and add instead.
Multiplication
A logical left shift of n bits will multiply a binary number by decimal
e.g. 00001111 (15) when shifted 2 bits to the left becomes 00111100 (60) which is exactly
Data
Registers
Registers are a fast form of storage which processors use to manipulate data. They are usually implemented with flip-flops, and while the costs is high, the speed benefits greatly.
Functions (C)
There are two types of functions, caller and callee. The caller function calls the callee function (think employer - employee). Both functions need to use the same sets of #Registers to execute the call, so we implement caller-saved and callee-saved or call-clobbered and call-perserved registers.
Call-Clobbered
Call-clobbered registers hold temporary values, aka. volatile data. So for that reason are saved by the caller function. This usually entails pushing them onto the stack or saving them to memory. It is fairly normal to let the callee function destroy values in these registers. The values can be restored after the callee function has finished executing.
Call-Preserved
Call-preserved registers hold values across calls, or non-volatile data. This puts the responsibility of preserving register values on the callee function as the caller function expects all register values to be unchanged when returned. The callee can access values from the caller with this method.
Within functions, all declared variables and assigned variables are put onto the stack unless static. All variables defined outside a function are defined in uninitialized data.
Definitions
Least Significant Bit
The least significant bit or LSB is the furthest right #Bit in a binary number. It is named as such due to its low "value".
Most Significant Bit
The most significant bit or MSB is the furthest left #Bit in a binary number. It is named as such due to its high "value".
Bit
A bit is a the smallest piece of information a modern computer can hold. A bit is a binary value that is usually represented as 1/0 but can also be represented as true/false, on/off, yes/no etc.
Bit is a portmanteau of binary digit.
Byte
A byte is a collection of 8 bits.
When put in an acronym a bit will be represented with a capital 'B'.
e.g 100 MB would be 'one hundred megabytes'
Reference
- Hoque, Tamzidul Various Lectures The University of Kansas 2024
- https://en.wikipedia.org/wiki/Bit