To convert to base 2, divide by 2 repeatedly and collect the remainders. Read them in reverse order, since the last remainder is the most significant bit.
13 ÷ 2 = 6 r 1
6 ÷ 2 = 3 r 0
3 ÷ 2 = 1 r 1
1 ÷ 2 = 0 r 1 → "1101"
The same algorithm converts to any base b: replace 2 with b. Remember the special case 0, which is "0" and not the empty string.