Binary Math Hacks

Questions

  1. 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?

    • To find the difference of two binary numbers, we can use the process of binary subtraction. Binary subtraction is similar to decimal subtraction, except that we use a base of 2 instead of 10. The following rules need to be followed for binary subtraction. For example, if the subtrahend (the number being subtracted) is larger than the minuend (the number being subtracted from), we need to borrow 1 from the next higher bit. Then, To borrow 1 from the next higher bit, we need to subtract 2 from that bit. For example, if we need to borrow 1 from the next higher bit in the number 10011010, we would subtract 2 from the second bit from the left, giving us 01111010. Once we have borrowed 1, we add 2 to the current bit to make up for the borrowed 1. For example, if we need to borrow 1 from the next higher bit in the number 10011010, and we are subtracting 1 from the rightmost bit, we would add 2 to that bit, giving us 1. We continue this process until we have subtracted all the bits in the subtrahend from the minuend.

Binary Table

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 |

Create Buttons





Binary Logic Hacks

Quiz

I needed some time to finish the quiz, and I used the notes as a guide. But I now have a good understanding of binary logic.

image

Coding Challenge

import csv

# Read the CSV file and extract the data into a list of integers
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])

# Calculate the mean of the original data
mean_orig = sum(data) / len(data)

# Iterate over the data and apply the rules
num_odds = 0
for i in range(len(data)):
    if data[i] % 2 == 1:
        data[i] = 0
        num_odds += 1
    elif data[i] % 5 == 0:
       data[i] *= 2

# Calculate the mean of the updated data
mean_updated = sum(data) / len(data)

# Print the results
print("Mean of original data: ", mean_orig)
print("Mean of updated data: ", mean_updated)
print("Number of odd elements: ", num_odds)
Mean of original data: 63.4
Mean of updated data: 69.1
Number of odd elements: 328

Logic Gates Hacks

Questions

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

    • Logic gates can be combined in various ways to perform basic computer functions such as arithmetic, logical operations, and memory storage. These functions are the building blocks of a computer's central processing unit (CPU).
  2. What is the difference between boolean operations and logic gates?(1-2 sentences)

    • Boolean operations are abstract logical operations performed on Boolean values (True or False) that result in another Boolean value. Logic gates, on the other hand, are physical electronic devices that perform Boolean operations on binary signals (0 or 1) and output a binary signal based on the input signal. While boolean operations are a mathematical abstraction, logic gates are physical devices used in electronic circuits to implement boolean operations.
  3. Complete this quiz and correct any mistakes in your blog

    • image
    • I got the first one wrong which is this one. I misread the question because I thought it was talking about AND and not OR.
    • image

Fetching Hacks

const data = [
  { id: 1, name: 'Alice', age: 27 },
  { id: 2, name: 'Bob', age: 32 },
  { id: 3, name: 'Charlie', age: 21 },
  { id: 4, name: 'David', age: 45 }
];

// Filter data based on age greater than 30
const filteredData = data.filter((item) => {
  return item.age > 30;
});

console.log(filteredData);
// Output: [{ id: 2, name: 'Bob', age: 32 }, { id: 4, name: 'David', age: 45 }]
{ id: 2, name: 'Bob', age: 32 }, { id: 4, name: 'David', age: 45 }

Github Pages Hacks

  1. Github pages is a hosting service website. Search up another hosting service website other than Github's and write at least one benefit, advantage, or feature at is different from other hosting service websites.
    • One hosting service website that is different from GitHub Pages is Netlify. Netlify is a platform that provides continuous deployment and hosting services for web projects. One of the main advantages of Netlify is that it offers a powerful and flexible build system that allows developers to build, test, and deploy their projects automatically. Netlify also provides features such as forms handling, identity management, and serverless functions, which allow developers to build and deploy dynamic web applications without the need for a separate backend server. Additionally, Netlify provides a global content delivery network (CDN) and SSL encryption by default, ensuring that web applications hosted on the platform are fast, secure, and highly available.

APIs Hacks

Take this python table and use a minimum of 3 pandas functions to analyze the data

import pandas as pd
data = {
    'Name': ['Dillon', 'Noor', 'Steven', 'Lucas', 'Harsha', 'Varalu', 'Ryan', 'Emaad'],
    'Age': [24, 31, 42, 27, 29, 26, 90, 15],
    'Gender': ['M', 'M', 'M', 'M', 'F', 'F', 'F', 'F'],
    'Grade': ['A', 'B', 'A', 'D', 'C', 'F', 'B', 'A']
}
df = pd.DataFrame(data)
print(df)

print(df.describe())

print(df.groupby('Gender').mean())

print(df['Grade'].value_counts())
     Name  Age Gender Grade
0  Dillon   24      M     A
1    Noor   31      M     B
2  Steven   42      M     A
3   Lucas   27      M     D
4  Harsha   29      F     C
5  Varalu   26      F     F
6    Ryan   90      F     B
7   Emaad   15      F     A
             Age
count   8.000000
mean   35.500000
std    23.268618
min    15.000000
25%    25.500000
50%    28.000000
75%    33.750000
max    90.000000
         Age
Gender      
F       40.0
M       31.0
A    3
B    2
D    1
C    1
F    1
Name: Grade, dtype: int64

Data Compression Hacks

Lossless compression algorithms typically work by finding patterns in the data and representing them with shorter codes, while ensuring that the compressed data can be perfectly reconstructed back to its original form. Examples of lossless compression algorithms include Huffman coding, Lempel-Ziv-Welch (LZW) compression, and DEFLATE.

On the other hand, lossy compression algorithms work by permanently discarding some data that is deemed less important or less noticeable to the human eye. This allows for a higher compression ratio, but the reconstructed data will not be exactly the same as the original data. Lossy compression is often used for media files such as images, audio, and video, where small visual or auditory imperfections are generally acceptable. Examples of lossy compression algorithms include JPEG, MP3, and MPEG.