Thread substr(): Alternative gesucht (15 answers)
Opened by bloonix at 2007-07-02 15:44

shigetsu
 2007-07-02 19:06
#78139 #78139
User since
2007-04-22
16 Artikel
BenutzerIn
[Homepage] [default_avatar]
Im ungewissen, obs denn relevant sei:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper qw(Dumper);

my $vector = '123456789';
my $bits = unpack 'b*', $vector;
my @bits = split //, $bits;

my @bytes;
while (@bits) {
    #my $byte = pack 'b8', join '', splice(@bits, 0, 8); # 1-byte (ascii)
    #my $byte = join '', splice(@bits, 0, 8); # 8-bit (bits)
    #my $byte = join '', splice(@bits, 0, 64); # 64-bit (bits)
    push @bytes, $byte;
}

print Dumper \@bytes;      


#1
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = [
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
];


#2
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = [
'10001100',
'01001100',
'11001100',
'00101100',
'10101100',
'01101100',
'11101100',
'00011100',
'10011100'
];


#3
Code: (dl )
1
2
3
4
$VAR1 = [
'1000110001001100110011000010110010101100011011001110110000011100',
'10011100'
];
\n\n

<!--EDIT|shigetsu|1183389239-->

View full thread substr(): Alternative gesucht