# picoCTF 2019 2Warm Writeup

2Warm is a General Skills puzzle worth 50 points.

## Description

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

## Solution

This puzzle is trivial to solve using an online tool such as RapidTables, but I figured I’d show how to do this by hand.

The process of doing this manually is relatively straightforward, but explaining it is a challenge for me, so I will attempt to do so now.

### Base 10 to Binary

The following chart represents the powers of 2 for 8 bits (one byte). The maximum value of one byte in decimal is 255: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

Since 42 is less than 1 byte, this chart is enough. If you are working with bigger numbers, extend this chart accordingly.

Now, work from left to right on this chart. If the number you wish to convert to binary is greater than or equal to the value in the column, place a 1 in this position. Otherwise, place a 0. Subtract the value in the column from the original number, and keep working your way to the right, carrying the remainder:

• 42 is less than 128 = 0
• 42 is less than 64 = 0
• 42 is greater than 32 = 1
• 42 – 32 = 10
• 10 is less than 16 = 0
• 10 is greater than 8 = 1
• 10 – 8 = 2
• 2 is less than 4 = 0
• 2 is equal to 2 = 1
• 2 – 2 = 0
• 0 is less than 1 = 0

This leaves us with `00101010`. Removing the leading zeroes, the answer is `101010`. Encompassing this with `picoCTF{}` yielded the correct flag.

To check that this is correct, 32 + 8 + 2 = 42.

Next, you simply refer every 4 bits (a nibble), to their corresponding hexadecimal value. `00101010` broken down into nibbles is `0010` and `1010`. Referring to the chart, 0010 is `2`, and 1010 is `a`. Therefore, 42 = 0x2a.