I am having trouble formatting my output of decimal to binary conversions in the format of XXXX XXXX and XX for hexadecimal using numbers 0 to 300. Does anyone have any ideas? Thanks in advance. Here is a copy of my output.


DECIMAL BINARY HEXADECIMAL
0 0 0
1 1 1
2 10 2
3 11 3
4 100 4
5 101 5
6 110 6
7 111 7
8 1000 8
9 1001 9
10 1010 a
11 1011 b

For a given base B, study what

y = x % B
x = x / B

does for you.

I am having trouble formatting my output of decimal to binary conversions...

Wouldn't it be beneficial to let us know what kind of problem you are having? The output you posted is correct.

Oh, was the problem just one of adjusting the widths of the outputs - I mis-read it then.

Assuming cout, look up the setw() IO manipulator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.