2Warm picoCTF 2019 Solution

Published: April 2, 2026

Description

Can you convert the number 42 (base 10) to binary (base 2)?

Solution

Want to try it yourself first?

The guided walkthrough reveals hints one step at a time.

Walk me through it
  1. Step 1
    Convert decimal to binary with Python
    Observation
    I noticed the challenge asks to convert 42 from base 10 to base 2, which suggested using Python's built-in bin() function as a quick, reliable one-liner rather than performing the repeated-division-by-2 conversion by hand.
    Open 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.
    python
    python3 -c "print(bin(42))"

    Expected output

    0b101010
    What didn't work first

    Tried: Submit '0b101010' as the flag, including the Python prefix.

    Python's bin() always prepends '0b' to indicate the base, but this prefix is not part of the numeric value. The flag format wraps only the raw binary digits, so picoCTF{0b101010} is rejected. Strip the prefix and submit picoCTF{101010}.

    Tried: Manually convert 42 to hex instead of binary, submitting '2a' as the answer.

    Hex (base 16) and binary (base 2) are different bases. Python's hex(42) returns '0x2a', which is the correct hexadecimal representation but wrong here. The problem explicitly asks for base 2, so only the bin() function or a manual repeated-division-by-2 process gives the right answer.

    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's bin() automates this and prepends 0b to 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 Python
    • hex(n) - decimal to hex string in Python
    • oct(n) - decimal to octal string in Python
    • int('101010', 2) - binary string back to decimal

    Bitwise operations - AND, OR, XOR, NOT, left shift, and right shift - all operate directly on the binary representation of numbers. XOR (^ in Python) is particularly important in cryptography and CTF challenges: XOR-ing a value with itself gives 0, XOR-ing with 0 gives the original value, and XOR is its own inverse (applying it twice cancels out). Many simple encryption schemes use XOR with a repeating key, which is vulnerable to frequency analysis when the key is short.

    Binary in network subnetting is another essential application. An IPv4 address like 192.168.1.1 is really four binary octets. A subnet mask like 255.255.255.0 (or /24 in CIDR notation) is a sequence of 24 ones followed by 8 zeros in binary: 11111111.11111111.11111111.00000000. ANDing an IP address with its subnet mask gives the network address. Understanding subnets at the binary level makes network security concepts like ACLs, firewall rules, and CIDR ranges much more intuitive.

    Signed vs. unsigned integers is a critical distinction in binary. An 8-bit unsigned integer represents 0-255. An 8-bit signed integer (two's complement) represents -128-127 - the most significant bit signals the sign. The value 11111111 in binary is 255 as unsigned but -1 as a signed 8-bit integer. This ambiguity is the source of many real-world vulnerabilities: integer overflows, sign confusion bugs, and type confusion errors in C/C++ code often stem from the boundary between unsigned value 128 (binary 10000000) being reinterpreted as -128 in a signed context.

Interactive tools
  • Base64 & Base32 DecoderDecode Base64 and Base32 strings with auto-detection. Multi-layer mode unwraps nested encodings automatically.
  • Recipe ChainStack decoders into a pipeline: Base64, hex, ROT, XOR, Morse, URL, Atbash, Vigenère, and more. Magic mode auto-discovers the chain. Bookmark the URL to save it.
  • Number Base ConverterConvert numbers between binary, octal, decimal, and hexadecimal instantly. Enter any value and see all four bases update in real time.
Alternate Solution

No Python handy? Use the Number Base Converter built into this site. Enter 42 in the decimal field and it instantly shows the equivalent in binary, hex, and octal - all at once.

Flag

Reveal flag

picoCTF{101010}

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.

Key takeaway

Every modern computer stores and processes all data in binary, making fluency with base-2 arithmetic foundational to security work. Number base conversions between binary, octal, decimal, and hexadecimal appear constantly in memory addresses, file permissions, network masks, and bitwise cryptographic operations. Signed versus unsigned integer distinctions in binary are also the root cause of a large class of real-world vulnerabilities, including integer overflows and type confusion bugs in C and C++ code.

Related reading

Want more picoCTF 2019 writeups?

Useful tools for General Skills

What to try next