in reply to bin2hex converter

Eh, is there a reason not to use pack/unpack? Assuming $_ contains a multiple of 8 bits (else, prepad with 0's), the following converts binairy to hexadecimal:
$hex = unpack ("H*", pack ("B*", $_));

-- Abigail

Replies are listed 'Best First'.
Re: Re: bin2hex converter
by Anonymous Monk on Jun 10, 2001 at 23:32 UTC
    No reason in particular. . . just trying it for fun. I was seeing how small I could get the code w/o using pack/unpack/modules
      Oh, you wanted to play golf? Well, how about:
      s/(.{1,4})(?=(?:.{4})*$)/sprintf"%x",eval"0b$1"/eg;

      -- Abigail

        ($;,$_,$|,$\)=("Yoo*se\x7F*cd*Mcpk+"," "x17,1,"\r"); {vec($_=>1+$"=>$^F<<$^F)=ord($/^substr$;=>$"=int rand 16=>1); print&&select$,,$,,$,,$|/($|+tr/ //c);redo if y/ //>$^F**2};