title: Convert a decimal number to hexadecimal and binary in a shell script
body: <p>I have a decimal number in each line of a <code>file.txt</code>:</p>
  
  <pre><code>    1
      2
      3
  </code></pre>
  
  <p>I am trying (for too long now) to write a one-liner script to have an output where each row has a column with the decimal, hexadecimal and the binary. To ease the task we can say that the original number is expressed in a byte. So the maximum value is 255.</p>
  
  <ol>
  <li><p>I first try to decode each number as a bynary with prepended 0 so to have an 8 bits pattern:</p>
  
  <p><code>awk '{print "ibase=10;obase=2;" $1}' $1 | bc | xargs printf "%08d\n"</code></p>
  
  <p>where the outer $1 in the awk statement is <code>file.txt</code>. The output is :</p>
  
  <pre><code>00000001
  00000010
  00000011
  </code></pre></li>
  <li><p>Same for hex with one prepended 0</p>
  
  <p><code>awk '{printf("0x%02x\n", $1)}' $1</code></p>
  
  <p>Same as before. The Output is :</p>
  
  <pre><code>0x01
  0x02
  0x03
  </code></pre></li>
  <li><p>Well, the decimal should be just a print:</p>
  
  <pre><code>1
  2
  3
  </code></pre></li>
  </ol>
  
  <p>What I'd like to have is one liner where I have:</p>
  
  <pre><code>    1 00000001 0x01
      2 00000001 0x02
  </code></pre>
  
  <p>so basically to put 1. 2. and 3. in each line of the output.</p>
  
  <p>I tried to execute bc (and other command) within awk using system() without success. And a zillion other ways. What is the way you would do it?</p>