Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>edit</strong> Checkers has reduced my C solution to <a href="https://stackoverflow.com/questions/795027/code-golf-hex-to-raw-binary-conversion/795944#795944">46 bytes</a>, which was then reduced to 44 bytes thanks to a tip from BillyONeal plus a bugfix on my part (no more infinite loop on bad input, now it just terminates the loop). Please give credit to Checkers for reducing this from 77 to 46 bytes:</p> <pre><code>main(i){while(scanf("%2x",&amp;i)&gt;0)putchar(i);} </code></pre> <p>And I have a much better Ruby solution than my last, in <del>42</del> <em>38</em> bytes (thanks to Joshua Swank for the regexp suggestion):</p> <pre><code>STDIN.read.scan(/\S\S/){|x|putc x.hex} </code></pre> <p><strong>original solutions</strong></p> <p>C, in 77 bytes, or two lines of code (would be 1 if you could put the <code>#include</code> on the same line). Note that this has an infinite loop on bad input; the 44 byte solution with the help of Checkers and BillyONeal fixes the bug, and simply stops on bad input.</p> <pre><code>#include &lt;stdio.h&gt; int main(){char c;while(scanf("%2x",&amp;c)!=EOF)putchar(c);} </code></pre> <p>It's even just 6 lines if you format it normally:</p> <pre><code>#include &lt;stdio.h&gt; int main() { char c; while (scanf("%2x",&amp;c) != EOF) putchar(c); } </code></pre> <p>Ruby, 79 bytes (I'm sure this can be improved): </p> <pre><code>STDOUT.write STDIN.read.scan(/[^\s]\s*[^\s]\s*/).map{|x|x.to_i(16)}.pack("c*") </code></pre> <p>These both take input from STDIN and write to STDOUT</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload