Logic Gates

  1. How can logic gates be used to execute basic computer functions?

Logic gates are essential components for building digital circuits and are crucial for basic computer operations. They utilize Boolean logic operations to process binary data, which enables complex decision-making processes.

  1. What is the difference between boolean operations and logic gates?

Boolean operations and logic gates are separate components, where the former is performed by the latter. Logic gates contain different types of Boolean operations such as AND, OR, NOT, and XOR, and use Boolean data to perform various functions.

  1. Complete this quiz and correct any mistakes in your blog

khan quiz

Binary Logic Hacks

binary quiz

import pandas as pd

df = pd.read_csv('files/random_numbers_1000.csv')
mean = df['number'].mean()
print(f"The mean of the data is {mean}")


filtered_sum = 0
count = 0
for num in df['number']:
    if num % 2 != 0:
        continue
    elif num % 5 == 0:
        num *= 2
    else:
        pass
    filtered_sum += num 
    count += 1

if count > 0:
    filtered_mean = filtered_sum / count
else:
    filtered_mean = 0

print(f"The mean of the filtered data is {filtered_mean}")
print(f"{count} numbers meet the first criteria")
The mean of the data is 0.4904628425744203
The mean of the filtered data is 0
0 numbers meet the first criteria

Github Pages Hacks

Firebase is a popular platform for website hosting that offers several benefits and a user-friendly interface. Its hosting features are fast, secure, and free, with reliable databases. It streamlines the app development process and provides backend services, resulting in a seamless full-stack experience. Firebase caters to individuals who need a platform for user-generated content and allows lossless transfers of documents, supporting various media formats such as images, audio, and video.

Conversion Exercises

Convert the following numbers to decimal notation:

  • 111: 7
  • 1011: 11
  • 10111011: 187
Binary Addition/Subtraction





Binary Math Hacks

Question: How do you think we should find the difference of two binary numbers? The product? The quotient? What rules need to be followed for those operations? Look into all of this on the Internet and note down important information you find (0.45)

  • The process for subtracting binary numbers is similar to subtracting base 10 numbers. When 1 is subtracted from 0, it's necessary to borrow 1 from the next higher bit, reducing that bit by 1, and leaving a remainder of 1.
  • When multiplying binary numbers, the product can either be the binary number itself or 0. To calculate, shift the non-zero multiplier to the left and add the shifted numbers together.
  • Dividing two binary numbers follows certain rules, and it is impossible to divide by 0. If the divisor is greater than the dividend, set the quotient to 0 and bring down the second bit of the dividend. However, if the dividend is larger, multiply the divisor by 1 and subtract the result. Then, find the remainder, repeat the first step, and continue until the remainder is 0.

Based on what you find online, fill out the tables below for subtracting, multiplying, and dividing binary numbers (0.45):

Subtracting Rules

|---------|---------|---------|---------| | 1-1 | 1-0 | 0-1 | 0-0 | | 0 | 1 | 1 | 0 |

Multiplying Rules

|---------|---------|---------|---------| | 1x1 | 1x0 | 0x1 | 0x0 | | 1 | 0 | 0 | 0 |

Dividing Rules

|---------|---------| | 1/1 | 0/1 | | 1 | 0 |

API Hacks

import requests

"""
RapidAPI is the world's largest API Marketplace. 
Developers use Rapid API to discover and connect to thousands of APIs. 
"""
url = "https://corona-virus-world-and-india-data.p.rapidapi.com/api"
headers = {
    'x-rapidapi-key': "26d9a3c8fbmshd1c8fc32ca8acc3p190a69jsn54f737b8e33b",
    'x-rapidapi-host': "corona-virus-world-and-india-data.p.rapidapi.com"
}

# Request Covid Data
response = requests.request("GET", url, headers=headers)
# print(response.text)  # uncomment this line to see raw data
# This code looks for "world data"
print("World Totals")
world = response.json().get('world_total')  # turn response to json() so we can extract "world_total"
for key, value in world.items():  # this finds key, value pairs in country
    print(key + ":", value)

print()

# This code looks for China in "countries_stats"
print("Country Totals")
countries = response.json().get('countries_stat')
for country in countries:  # countries is a list
    if country["country_name"] == "China":  # this filters for China
        for key, value in country.items():  # this finds key, value pairs in country
            print(key + ":", value)
World Totals
total_cases: 509,268,964
new_cases: 204,268
total_deaths: 6,242,509
new_deaths: 630
total_recovered: 461,827,849
active_cases: 41,198,606
serious_critical: 42,510
total_cases_per_1m_population: 65,334
deaths_per_1m_population: 800.9
statistic_taken_at: 2022-04-24 11:18:01

Country Totals
country_name: China
cases: 200,654
deaths: 4,725
region: 
total_recovered: 166,398
new_deaths: 39
new_cases: 1,580
serious_critical: 236
active_cases: 29,531
total_cases_per_1m_population: 139
deaths_per_1m_population: 3
total_tests: 160,000,000
tests_per_1m_population: 111,163

Fetching Hacks

students = [
    {"name": "Billy", "age": 20, "major": "Computer Science"},
    {"name": "Bob", "age": 22, "major": "Mathematics"},
    {"name": "Joe", "age": 19, "major": "Physics"}
]

# sort the list of dictionaries by age
age_sorted = sorted(students, key=lambda student: student["age"])

# fetch data from the sorted list of dictionaries and print it
for student in age_sorted:
    print("Name:", student["name"])
    print("Age:", student["age"])
    print("Major:", student["major"])
    print()
Name: Joe
Age: 19
Major: Physics

Name: Billy
Age: 20
Major: Computer Science

Name: Bob
Age: 22
Major: Mathematics