Perl Binary turn Hex

Discussion in 'Programmer's Corner' started by Anthony Quah, Aug 3, 2010.

  1. Anthony Quah

    Thread Starter Active Member

    Dec 1, 2007
    80
    0
    hi guy,

    Need some advice, i try convert Inputfiles.txt which is in binary to Hex into output files but keep getting the value add together.

    Inputfiles.txt
    PA 110011011
    PB 000101
    PC 111111111100


    The output should look exactly like this like this even with PA,PB and PC (Outputfiles.txt)
    PA 19B
    PB 05
    PC FFC


    My command : Bin2Hex.pl Inputfiles.txt Outputfiles.txt
    I need some help/advice from you guy what is the wrong with my coding. Please view attachment.. sorry unable to upload in .pl extension I write it as .txt instead
     
  2. Anthony Quah

    Thread Starter Active Member

    Dec 1, 2007
    80
    0
    anyone can help on this?
     
  3. coldpenguin

    Active Member

    Apr 18, 2010
    165
    9
    I would start with a change like this, but it is possibly just the way I code
    Code ( (Unknown Language)):
    1.  
    2.    while ($b=<IN>) {
    3.         ($name,$val)=split(/\s/,$b);
    4.       $n = length($b);
    5.       $byteCount += $n;
    6.       $s = 2*$val;
    7.       print (OUT "$name ".unpack("H$s", $val), "\n");
    8.    }
    9.  
     
Loading...