5
$\begingroup$

I have the numbers $0-64$ in binary and want them all to be displayed with 8 figures.

Expected output:

$5_{10} = 101_2$ should become 00000101.

$\endgroup$
  • 2
    $\begingroup$ IntegerString[5, 2, 8] $\endgroup$ – swish May 25 '17 at 15:48
  • $\begingroup$ is the expected output a String? or more like BaseForm which affects printing but not evaluation? $\endgroup$ – rhermans May 25 '17 at 15:51
  • 1
    $\begingroup$ Related: (6635) $\endgroup$ – Mr.Wizard May 25 '17 at 21:37
7
$\begingroup$

It's unclear in your question if you are asking for a String for NumberForm.

FORM

If you want to change the Form but not create a string then

NumberForm[BaseForm[Range[0, 64], 2], 8, NumberPadding -> {"0", "0"}]

Mathematica graphics

you could define a function

bin8[n_Integer] := NumberForm[
  BaseForm[n, 2]
  , 8
  , NumberPadding -> {"0", "0"}
  ]

bin8 /@ Range[0, 64]

And get the same output

STRING

As pointed out by @swish

IntegerString[Range[0, 64], 2, 8]

Mathematica graphics

$\endgroup$
3
$\begingroup$

how about

Row /@ Tuples[{0, 1}, 8][[;; 65]]

{00000000,00000001,00000010,00000011,00000100,00000101,00000110,00000111,00001000,00001001,00001010,00001011,00001100,00001101,00001110,00001111,00010000,00010001,00010010,00010011,00010100,00010101,00010110,00010111,00011000,00011001,00011010,00011011,00011100,00011101,00011110,00011111,00100000,00100001,00100010,00100011,00100100,00100101,00100110,00100111,00101000,00101001,00101010,00101011,00101100,00101101,00101110,00101111,00110000,00110001,00110010,00110011,00110100,00110101,00110110,00110111,00111000,00111001,00111010,00111011,00111100,00111101,00111110,00111111,01000000}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.