Easy · Math

Convert Decimal to Base N

Given an integer n and a base between 2 and 16, return n written in that base using the digits 0–9 and A–F, with a leading '-' when n is negative and "0" when n is 0.

Examples

Example 1

{
  "n": 45,
  "base": 16
}

Output: 2D

Example 2

{
  "n": 13,
  "base": 2
}

Output: 1101

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Math problems