1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #!/usr/bin/perl
use strict;
use warnings;
my $hex2bin={ '0' => '0000',
'1' => '0001',
'2' => '0010',
'3' => '0011',
'4' => '0100',
'5' => '0101',
'6' => '0110',
'7' => '0111',
'8' => '1000',
'9' => '1001',
'A' => '1010',
'B' => '1011',
'C' => '1100',
'D' => '1101',
'E' => '1110',
'F' => '1111'};
my $bin2hex={ '0000' => '0',
'0001' => '1',
'0010' => '2',
'0011' => '3',
'0100' => '4',
'0101' => '5',
'0110' => '6',
'0111' => '7',
'1000' => '8',
'1001' => '9',
'1010' => 'A',
'1011' => 'B',
'1100' => 'C',
'1101' => 'D',
'1110' => 'E',
'1111' => 'F'};
my $test="123456789ABCDEF00000000000000002F4A12F4A12F4A12F4A12F4A12F4A";
my $test2="";
print "test (hex): $test \n";
#conversion binaire
$test=~s/(.)/$hex2bin->{$1}/g;
print "test (bin): $test \n";
#multiplication par 2
$test2="000".$test."0";
print "test2 (bin): $test2 \n";
#conversion retour en hexa
$test2=~s/(....)/$bin2hex->{$1}/g;
print "test2 (hex): $test2 \n"; |
Partager