Numbers and bits · 6 / 15 Exercise Easy

Convert to base b

Objective

The same number can be written in any base. To convert it from decimal to base b, divide by the base and keep the remainders, from last to first.

Instructions

  • The first line has the number t of cases. Each case is a line with n and b (between 2 and 16).
  • Show n written in base b, using the digits 0-9A-F (uppercase letters). Do not use bin or format.
Input
3
10 2
255 16
0 8
Output
1010
FF
0

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise