Binary Math

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)

In order to find the difference of two binary numbers, the borrowing method needs to be used. After researching, I found that this was the best and easy way that made sense to me. First, you subtract the right binary number and the right binary number from the minued. In some cases, depending on the number you need to borrow from the left and add two to the minued. The next step is to just subtract the remaining numbers and borrow depending on the circumstance. To find the product of binary numbers, its like decimal multiplcation. So, you multiply one number by the other and you add the product results. To find the quotient, you need to divide both the binary numbers, using long division and dividing decimals. Then, this all leads to your quotient of the binary numbers.

Subtracting Binary Numbers Rules

1-1 1-0 0-1 0-0
0 1 1 0

Multiplying Binary Numbers Rules

1x1 1x0 0x1 0x0
1 0 0 0

Dividing Binary Numbers Rules

1/1 0/1
1 0

submenu_pic

Here, I made a submenu on my blog for all 3 buttons, multiply, divide, and subtract.

Binary Logic

quizresults

I got 12/12 on the quiz and the quiz took me awhile to complete because I had to reference the notes on the website and reread them to understand them thoroughly.

Coding Challenges

import csv

data = []
with open('random_numbers_1000.csv', 'r') as files:
    reader = csv.reader(files)
    for row in reader:
        data.extend([int(num) for num in row])

meanCalc = sum(data) / len(data)

oddNumbers = 0
for i in range(len(data)):
    if data[i] % 2 == 1:
        data[i] = 0
        oddNumbers += 1
    elif data[i] % 5 == 0:
       data[i] *= 2

updateMean = sum(data) / len(data)

print("Mean of CSV File Data: ", meanCalc)
print("Mean of New Data: ", updateMean)
print("Amount of Odds: ", oddNumbers)
Mean of CSV File Data: 63.6
Mean of New Data: 69
Amount of Odds: 358

Logic Gates

1.How can logic gates be used to execute basic computer functions?(1-2 sentences)

Logic gates can be used to execute basic computer functions by being combined to perform basic computer functions. They can often perform functions like arithmetic operations, data storage, and decision making.

2.What is the difference between boolean operations and logic gates?(1-2 sentences)

The difference between boolean expressions and logic gates is that boolean operations are mathematical functions used on boolean values. Whereas, logic gates are the realization of Boolean operations. Logic gates process binary data in a computer by performing Boolean logic operations like AND, OR, NOT, and XOR.

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

khanaquiz

Fetching

data = [
  { id: 1, name: 'Bob', grade: 11 },
  { id: 2, name: 'Bill', grade: 9 },
  { id: 3, name: 'Maxwell', grade: 9 },
  { id: 4, name: 'Maxine', grade: 10 },
  { id: 5, name: 'Sally', grade: 9 },
  { id: 6, name: 'Mary', grade: 12 }

];
const filterGrades = data.filter((item) => {
  return item.grade > 10;
});

console.log(filterGrades);
{ id: 1, name: 'Bob', grade: 11}, { id: 6, name: 'Mary', grade: 12 }

Github Pages

Another hosting service website other than Github is GoDaddy. GoDaddy is a website hosting service that includes free domain and SSL. A benefit and advantage of GoDaddy is its user-friendly website builder. It allows users to easily create and customize professional websites without needing coding or technical expertise. This feature sets it apart from other hosting services website that may require more technical knowledge to create a website. This is just one example of a hosting service website, there are several more such as Netlify, which has its own benefits, advantages, and features.

APIs

import requests
from tabulate import tabulate


url = "https://country-location-api.p.rapidapi.com/location"

querystring = {"country":"canada"}

headers = {
	"content-type": "application/octet-stream",
	"X-RapidAPI-Key": "8ca68e698emsh077b34dcb5cedc7p176bfdjsn4a11c2cb1bef",
	"X-RapidAPI-Host": "country-location-api.p.rapidapi.com"
}
table = [['Country', 'Capital', 'Currencies', 'Languages', 'Population', 'Region', 'Subregion'], 
         ['Canada', 'Ottawa', 'Canadian Dollars', 'English, French', 38005238, 'Americas', 'Northern America'], 
         ['United States', 'Washington DC', 'US Dollars', 'English', 58005238, 'Americas', 'Northern America'], 
         ['Mexico', 'Mexico City', 'Pesos', 'Spanish', 1269362, 'Americas', 'Southern America']]
response = requests.get(url, headers=headers, params=querystring)

print(response.json())
print(tabulate(table))
{'location': {'capital': 'Ottawa', 'currencies': ['Canadian dollar'], 'languages': ['English', 'French'], 'name': 'Canada', 'population': 38005238, 'region': 'Americas', 'subregion': 'Northern America'}}
-------------  -------------  ----------------  ---------------  ----------  --------  ----------------
Country        Capital        Currencies        Languages        Population  Region    Subregion
Canada         Ottawa         Canadian Dollars  English, French  38005238    Americas  Northern America
United States  Washington DC  US Dollars        English          58005238    Americas  Northern America
Mexico         Mexico City    Pesos             Spanish          1269362     Americas  Southern America
-------------  -------------  ----------------  ---------------  ----------  --------  ----------------

This is a third party API about country location and details that I used above.

Data Compression

Lossless images are in a JPG image format, consisting of lossy data. JPGs are always in a lossless format. They work by shorter code segments that are compressed and also go back into their original form. A few examples of lossless compression algorithms include deflate and Huffman coding.

Whereas lossy image, which means it is in a PNG format. PNG uses a compression algorithm which keeps the picture's original data without information/data being lost. Lossy algorithms work by removing the unneccesary data and unimportant data, this plays a key role in compression. This type of compression can be seen in audious and pictures and examples of lossy compression algorithms include MP3 and JPEG files.

This is an example of a lossy versus lossless data compression.

exampleoflossyvlossless

The Game

thegame

Level 1:

  • The first level works that the way it is because the result of the first one is 1 due to XOR. Knowing this, that part must be equal to 0. I also used the truth table, which is how I got to the answer XOR.

Level 2:

  • The second level works the way it does because the XNOR gate is a product of 1 being 0 and 0. The or gate has inputs of 1 and 0, with a product of 0. Adding the combination of XNOR and NAND gates produces the result.