------ VARIABLES ------
type some examples of variables in here...
age=15 #int
temp=10.5 #float
name="katie" #string
stuffBack= True #boolean
fruits = ["apple", "banana", "orange"] #list
myVariable= None #add value later
------ LIST (ARRAY) ------
Type an example of a List in here....
numbers = [1,2,3,4,5]
print(numbers)
mixedList= [1, "hi", 15.1, True]
print(mixedList)
# for the list you can change it to print different things
# Accessing an element by index
first_number = numbers[0] #-> 0 represents the first number from numbers list (1)
print(first_number) # Outputs: 1
# Modifying an element
numbers[2] = 99 #-> this makes the second value 99 instead (0,1,2) 3 turns to 99
print(numbers) # Outputs: [1, 2, 99, 4, 5]
# Append a new item to the list
numbers.append(6) # the 6 adds the number 6 onto the end of the list
print(numbers) # Outputs: [1, 2, 99, 4, 5, 6]
# Insert an item at a specific position
numbers.insert(2, 50) # Insert 50 at index 2
print(numbers) # Outputs: [1, 2, 50, 99, 4, 5, 6]
# Length of the list
print(len(numbers)) # Outputs: 5 - counts the ammount of nubmers in the list
# Check if an item exists in the list
print(5 in numbers) # Outputs: True
# 5 in numbers checks if 5 is presented in the list numbers- in keyword refers to boolean language - 5 is in the list so it will print true but if you said print(10 in numbers) then it would be false because 10 isnt in the list
------ INPUT ------
How to get a Users input and print out to the screen in here....
userInput = input(" please enter something")
print("you entered: ", userInput)
numberInput = int(input("please enter your first number: "))
print("your number was: ", numberInput)
------ FUNCTION ------
Create a function that prints something out to the screen....
def say_hello():
print("Hello, World!")
say_hello()
------ BINARY VALUES ------
0 → 0 0 0 0
1 → 0 0 0 1
2 → 0 0 1 0
3 → 0 0 1 1
4 → 0 1 0 0
5 → 0 1 0 1
6 → 0 1 1 0
7 → 0 1 1 1
8 → 1 0 0 0 ... one 8 and nothing else
------ TWO'S SCOMPLIMENT ------
To find the 2's complement of a binary number, follow these quick steps:
1. **Invert all the bits**: Flip all the 0s to 1s and all the 1s to 0s.
2. **Add 1** to the result of the inversion.
For example:
- **Original number**: 0101 (5 in decimal)
1. Invert the bits: 1010
2. Add 1: 1010 + 1 = 1011 (This is -5 in decimal)
That's the 2's complement of 0101.
------ BINARY ------
128 64 32 16 8 4 2 1
--- OVER FLOW ---
Overflow occurs when a value exceeds the maximum limit that can be represented with the available number of bits. For example,
if you're using 4 bits to represent numbers, the largest value you can store is 15 (1111 in binary).
If you try to store a value like 16, it exceeds the 4-bit limit and causes an overflow, resulting in incorrect or wrapped-around values.
--- HEXADECIMAL ---
gives 16 values maps nicely to 8 bits
--- SIZES ---
Sure! Here's a breakdown of values in bits for each unit:
- **Bit**: 1 bit
- **Nibble**: 4 bits
- **Byte**: 8 bits
- **Kibibyte (KiB)**: 1,024 bytes = 8,192 bits
- **Mebibyte (MiB)**: 1,024 KiB = 1,048,576 bytes = 8,388,608 bits
- **Gibibyte (GiB)**: 1,024 MiB = 1,073,741,824 bytes = 8,589,934,592 bits
Let me know if you'd like any more details!
------ HARDWARE CPU RAM ETC ------
### **Von Neumann Stored Program Concept**
- The computer **stores both programs and data in memory (RAM)**. The CPU fetches these instructions one by one to execute them.
### **Components and Their Roles**:
1. **Main Memory (RAM)**:
- **Stores programs and data** the CPU needs to work with.
2. **CPU**:
- **Control Unit (CU)**: **Manages everything** in the CPU, telling it what to do.
- **Arithmetic Logic Unit (ALU)**: Does **math and logic calculations**.
- **Registers**: **Temporarily store data** the CPU is working with.
3. **Clock**:
- Keeps things **timed** so the CPU knows when to do each step.
4. **Address Bus**:
- **Sends memory addresses** to tell where to get data from in RAM.
5. **Data Bus**:
- **Moves data** between the CPU and RAM.
6. **Control Bus**:
- **Sends control signals** to keep everything working together.
### **Fetch-Decode-Execute Cycle**:
1. **Fetch**: CPU gets the next instruction from memory.
2. **Decode**: CPU figures out what to do with the instruction.
3. **Execute**: CPU does the action (like a calculation).
And then it repeats for the next instruction!
--- STORAGE ---
1. **Magnetic Storage**:
- **Example**: Hard drives (HDDs).
- **How it works**: Uses magnets to read and write data on spinning disks.
2. **Optical Storage**:
- **Example**: CDs, DVDs.
- **How it works**: Uses lasers to read and write data on shiny discs.
3. **Solid State Storage**:
- **Example**: SSDs, USB flash drives.
- **How it works**: Uses memory chips (like flash) to store data without moving parts.
------ HEX EXPLAINED ------
Hexadecimal is the number base 16.
In decimal (base 10), we have 10 possible values for each digit, from 0 to 9.
So we start counting in the units column, and we can count from 0 to 9.
But if we add one more to 9, we run out of digits, so the units column loops back to 0 and we “carry” into the tens column,
giving us 1 ten and 0 units, which we write as 10.
The same thing applies as we increment the tens column, except when the tens column overflows, we carry into the hundreds column, etc.
Now with hexadecimal (base 16) we allow 16 values for each digit.
The first ten digits are the same as decimal, i.e 0 to 9.
But then we allow 6 more values, which are represented with letters A to F.
A hex = 10 decimal
B hex = 11 decimal
C hex = 12 decimal
D hex = 13 decimal
E hex = 14 decimal
F hex = 15 decimal
Now because we are allowing 16 instead of 10 digits in each column, the values of the columns are not powers of 10 (hundreds, tens, units etc) as they are in decimal, but rather powers of 16 (65536s, 4096s, 256s, 16s, units etc).
So to convert a hex number into decimal....
// HEX Number Columns
65536s, 4096s, 256s, 16s, units
Example would be:
2B7 in hex = (2×256) + (11×16) + (7×1)
2 B 7
which is: 512 + 176 + 7 = 695
We were doing F4 which would be...
F4 in hex = (15×16) + (4×1)
F 4
which is: 240 + 4 = 244
Chat GPT - Click for help with Code