Thread python nach perl -> pack / unpack (10 answers)
Opened by egal123 at 2015-12-09 19:41

Linuxer
 2015-12-10 12:47
#183202 #183202
User since
2006-01-27
3870 Artikel
HausmeisterIn

user image
Hi,

hier vielleicht etwas kürzer:

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


# convert values into bitstring (check sizes before!)
my $bits = sprintf( "%05b%01b%010b%08b", 2, 0, 64, 2 );

print $bits, "\n";

# split bitstring into bitstring per byte (length of $bits MUST be a multiple of 8)
my @bytes = $bits =~ m/([01]{8})/g;

print "String: $_\n"    for @bytes;

# convert bitstrings to numbers
@bytes = map { oct "0b$_" } @bytes;

print "Number: $_\n"    for @bytes;

Last edited: 2015-12-10 13:45:09 +0100 (CET)
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread python nach perl -> pack / unpack