Description
Can you convert the number 42 (base 10) to binary (base 2)?
Solution
- Step 1Convert decimal to binary with PythonOpen a Python shell and call bin(42). Python returns '0b101010' -- the '0b' prefix signals binary notation and is not part of the answer. Strip it off: the flag is 101010.python3 -c "print(bin(42))"
Learn more
Binary (base 2) is the numeral system used internally by every digital computer. Each digit, called a bit, can only be 0 or 1, corresponding to off and on states in electronic circuits. Groups of 8 bits form a byte, the fundamental unit of data storage and transmission.
Converting from decimal to binary is done by repeatedly dividing by 2 and recording remainders. For 42: 42 ÷ 2 = 21 R0, 21 ÷ 2 = 10 R1, 10 ÷ 2 = 5 R0, 5 ÷ 2 = 2 R1, 2 ÷ 2 = 1 R0, 1 ÷ 2 = 0 R1. Reading the remainders from bottom to top gives
101010. Python'sbin()automates this and prepends0bto signal the base.Knowing how to convert between number bases is essential in CTF and security work. Hexadecimal (base 16) is used for memory addresses and color codes. Octal (base 8) appears in Unix file permissions. Binary shows up directly in bitwise operations, network subnetting, and binary exploitation.
bin(n)-- decimal to binary string in Pythonhex(n)-- decimal to hex string in Pythonoct(n)-- decimal to octal string in Pythonint('101010', 2)-- binary string back to decimal
Flag
picoCTF{...}
Binary is base-2 -- each digit is a power of 2. Python's bin() function shows a '0b' prefix which is not part of the answer.