Binary Calculator
Perform arithmetic and bitwise operations on binary, decimal, and hexadecimal numbers.
Perguntas Frequentes
Implementação de Código
# Binary/Octal/Decimal/Hex conversions and arithmetic
# Convert decimal to other bases
n = 42
print(bin(n)) # 0b101010
print(oct(n)) # 0o52
print(hex(n)) # 0x2a
# Convert from binary/octal/hex to decimal
print(int("101010", 2)) # 42 (binary)
print(int("52", 8)) # 42 (octal)
print(int("2a", 16)) # 42 (hex)
# Format without prefix
print(format(42, "b")) # 101010
print(format(42, "o")) # 52
print(format(42, "x")) # 2a
print(format(42, "08b")) # 00101010 (zero-padded 8 bits)
# Binary arithmetic
a = 0b1010 # 10
b = 0b0110 # 6
print(bin(a + b)) # 0b10000 (16)
print(bin(a - b)) # 0b100 (4)
print(bin(a * b)) # 0b111100 (60)
print(a // b) # 1 (integer division)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.