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