>[оверквотинг удален]
>>$i=1;
>>
>>while (not eof file1) {
>>$a=getc file1; #Считываем ОДИН байт из файла. Абсолютно безразлично в какой он кодировке.
> Тут Вы считываете 1 байт, это понятно.
>>print "Number of read $i deccode $a bincode " . dec2bin(ord($a))."\n";
> Эта строчка мне совсем непонятна если честно - Там где bincode Вы
> вызываете функцию преобразования в 2ичную систему из десятичной если верить cookbook
> которую я и использовала, но я не вижу преобразования в в
> 10тичную систему, т.е. функция тут мне кажется странной.Это оно? :
#! /bin/usr/perl
open(file1, "text.txt");
binmode(file1);
$i=1;
while (not eof file1) {
$a1=ord getc file1;
$a2=ord getc file1;
$a3=ord getc file1;
$a4=ord getc file1;
$a5=ord getc file1;
$a6=ord getc file1;
$a7=ord getc file1;
$a8=ord getc file1;
$a=$a1.$a2.$a3.$a4.$a5.$a6.$a7.$a8;
print "Number of read $i deccode $a bincode ". bin2dec($a)." char ". chr(bin2dec($a)). "\n";
$i++; }
sub bin2dec {
return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
};
=================================================
Number of read 1676 deccode 01011000 bincode 88 char X
Number of read 1677 deccode 11100011 bincode 227 char у
Number of read 1678 deccode 01101111 bincode 111 char o
Number of read 1679 deccode 10010001 bincode 145 char С
Number of read 1680 deccode 01101011 bincode 107 char k
Number of read 1681 deccode 00110011 bincode 51 char 3