Binary Math and Truth Tables
Binary Math Hacks
Binary subtraction involves subtracting the smaller number from the larger using specific rules: if the digit being subtracted is 0, the result is the same as the minuend digit; if the digit being subtracted is 1 and the minuend digit is also 1, the result is 0; if the digit being subtracted is 1 and the minuend digit is 0, we borrow 1 from the next digit in the minuend, subtracting it from the minuend digit, with the result being 1. Binary multiplication involves multiplying each digit of the second number by each digit of the first number, shifted one place to the left for each digit, and then adding up all the results to get the final product. Binary division involves dividing the dividend by the divisor, starting from the left, and writing the quotient for each step. If the dividend is smaller than the divisor, write a 0 in the quotient and bring down the next digit of the dividend. If the dividend is larger than or equal to the divisor, divide the dividend by the divisor and write the quotient in the quotient column. Repeat the process until there are no more digits to bring down.
Exercises:
1-1 = 0
1-0 = 1
0-1 = 1
0-0 = 0
1x1 = 1
1x0 = 0
0x1 = 0
0x0 = 0
1/1 = 1
0/1 = 0
Here's a code segment which takes 2 binary numbers, subtracts them, and returns it in both decimal and binary.
def subtract_binary(num1, num2):
diff = bin(int(num1, 2) - int(num2, 2))[2:]
dec_diff = int(diff, 2)
return diff, dec_diff
num1 = '101'
# 101 in decimal = 5
num2 = '11'
# 11 in decimal = 3
diff, dec_diff = subtract_binary(num1, num2)
print("Here's the difference in binary:", diff)
print("Here's the difference in decimal:", dec_diff)
import pandas as pd
df = pd.read_csv('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")
Logic Gates Hacks
Logic gates are the basic building blocks of digital circuits that can be combined to implement Boolean functions and perform basic computer operations like addition, subtraction, multiplication, and division.
Boolean operations are operations that work on binary values, while logic gates are physical devices that implement Boolean functions in digital circuits. In simpler terms, Boolean operations are abstract concepts, while logic gates are tangible components used to build digital circuits that perform Boolean operations.
Fetching Hacks
data = [
{"User ID": 101, "Username": "johndoe", "Email": "johndoe@example.com", "Age": 25, "Country": "United States"},
{"User ID": 102, "Username": "janedoe", "Email": "janedoe@example.com", "Age": 31, "Country": "Canada"},
{"User ID": 103, "Username": "bobsmith", "Email": "bobsmith@example.com", "Age": 45, "Country": "United Kingdom"},
{"User ID": 104, "Username": "sarahjane", "Email": "sarahjane@example.com", "Age": 27, "Country": "Australia"}
]
def filter_by_age(data, min_age, max_age):
filtered_data = []
for row in data:
age = row["Age"]
if age >= min_age and age <= max_age:
filtered_data.append(row)
return filtered_data
filtered_data = filter_by_age(data, 25, 35)
print(filtered_data)
Github Pages Hacks
One hosting service website that is different from Github is GitLab. GitLab is a hosting service website that offers source code management and other DevOps-related features. One of its unique features is the integrated continuous integration and deployment (CI/CD) functionality, which allows users to automate the building, testing, and deployment of their applications. This feature helps teams save time and resources while improving the quality and reliability of their software.
API Hacks
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)
# Filter by Age greater than 30
age_filter = df[df['Age'] > 30]
print(age_filter)
# Filter by Gender is 'F'
gender_filter = df[df['Gender'] == 'F']
print(gender_filter)
# Filter by Grade is 'A' or 'B'
grade_filter = df[df['Grade'].isin(['A', 'B'])]
print(grade_filter)