Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bin.c #11662

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Convert binary to decimal
binary_num = '101010' # Example binary number
decimal_num = int(binary_num, 2)
print(f"The decimal equivalent is: {decimal_num}")

# Performing bitwise operations
a = 5 # 101 in binary
b = 3 # 011 in binary

# Bitwise AND
print(f"Bitwise AND: {a & b}")

# Bitwise OR
print(f"Bitwise OR: {a | b}")

# Bitwise XOR
print(f"Bitwise XOR: {a ^ b}")

# Bitwise NOT
print(f"Bitwise NOT of a: {~a}")

# Left shift
print(f"Left shift of a by 1: {a << 1}")

# Right shift
print(f"Right shift of a by 1: {a >> 1}")