#C12713. Decimal Base Conversion
Decimal Base Conversion
Decimal Base Conversion
You are given a non-negative integer n in decimal (base-10). Your task is to convert it into three different numeral systems:
- Binary (base-2)
- Octal (base-8)
- Hexadecimal (base-16) in uppercase
For a given input integer, print its binary, octal, and hexadecimal representations in one line separated by a single space.
Note: When converting to any base, if the number is 0
, the output should be 0
(i.e. no leading zeros).
The conversion algorithms can be represented mathematically as follows:
For any base \(b\) (where \(b\) is 2, 8, or 16) and a non-negative integer \(n\), the representation \(d_k d_{k-1} \ldots d_0\) satisfies \[ n = d_k\times b^k + d_{k-1}\times b^{k-1} + \cdots + d_0\times b^0, \] where each digit \(d_i\) is in the range \(0 \le d_i < b\), and for hexadecimal, digits greater than 9 are represented by uppercase letters A-F.
inputFormat
The input consists of a single line containing a non-negative integer n (0 ≤ n ≤ 109).
outputFormat
Output a single line with three values separated by a single space:
- Binary representation of n
- Octal representation of n
- Hexadecimal representation of n (in uppercase)
156
10011100 234 9C