1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my @array;
...
<geheimnissvolle Perl-Magie>
...
for (my $i = 0; $i < 8; $i++) {
printf("byte $i: %02x\n", $array[$i]);
}
--------------------------------
$ perl script.pl
byte 0: ff
byte 1: 1f
byte 2: 03
byte 3: 00
byte 4: 00
byte 5: 00
byte 6: 00
byte 7: 00
1
2
3
for (my $i = 0; $i < 8; $i++) {
$array[$i] = ( $number % ( 0x100 ** (1 + $i) ) / ( 0x100 ** $i ) );
}
1
2
3
for (my $i = 0; $i < 8; $i++) {
$array[$i] = ( $number % ( 0x100 << (8 * $i) ) / ( 0x1 << (8 * $i) ) );
}
QuoteIch habe eine große Integerzahl, z.B.
1
2
my @array = unpack( "C8", pack( "Q<", 0xf8f7f6f5f4f3f2f1 ) );
print( join( ", ", @array ), "\n" ); # 241, 242, 243, 244, 245, 246, 247, 248
1
2
3
use bigint;
my @array = unpack( "C16", pack( "Q<2", 0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0 ) );
print( join( ", ", @array ), "\n" ); # 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0
1 2 3 4 5 6 7 8 9 10 11
#! /usr/bin/perl use strict; use warnings; use 5.024; use bigint; ### ACHTUNG: Wechsel von < nach > zur schöneren Darstellung des Ergebnis my @array = unpack( "C16", pack( "Q>2", 0xfffefdfcfbfaf9f8, 0xf7f6f5f4f3f2f1f0 ) ); print( join( ", ", @array ), "\n" ); # 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240
2019-02-15T18:53:47 LinuxerWoher kommen denn die Integer-Werte?
1 2 3
my $device = "/dev/sda"; open my $handle, '<', $device or die "open($device,ro) failed: $!";
open( HANDLE, ...
open( my $handle ...
1 2 3
use IO::File; my $fh = IO::File->new; $fh->open($path, O_BINARY|O_RDONLY) or die $!;