Using pack and unpack to convert decimal number to binary number back and forth : unpack « System Functions « Perl






Using pack and unpack to convert decimal number to binary number back and forth

      

$decimal = 4;
$binary = unpack("B32", pack("N", $decimal));
$newdecimal = unpack("N", pack("B32", $binary));
print $newdecimal;

   
    
    
    
    
    
  








Related examples in the same category

1.pack and unpack.
2.Pack to hex string and unpack
3.Combine unpack and pack in one statement
4.The Template pack and unpack Types and Values