Guest User

Untitled

a guest
Jun 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. $str = '5B CD 02 01 10'; #Initialize my variable:in my function, this is passed as input
  2. $OldByte_str = substr($str,0,2); #extract the two characters to form a Byte
  3. $PDM_OldBits = ( "Binary: %bn", $PDM_OldByte );#Convert to binary. Supposed to give '0101 1011'
  4. substr($PDM_OldBit,2,2)= '10'; #Replace two bits.Supposed to give '01**10** 1011'
  5. $NewByte_str= sprintf("0x%x", stringdecimal(arraystring($PDM_OldBits)));#Convert back to Bytes. Supposed to give'6B'
  6. substr($str,0,2)= $PDM_NewByte;#Substitute back into the original Bytes string.Supposed to give: '**6B** CD 02 01 10'
  7.  
  8. sub stringdecimal {
  9. return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
  10. }
  11.  
  12. sub arraystring {
  13. my $string = join('', @_);
  14. return $string;
  15. }
Add Comment
Please, Sign In to add comment