加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

把二进制翻译成中文/英文

发布时间:2020-12-15 21:10:23 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/perl -w#use diagnostics;sub bin2cn{die "Error:1001:bin2cnn" if chop($_[0]) eq "";@hexi = bin2hex($_[0]);while(@hexi){$q=shift @h

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/usr/bin/perl -w
#use diagnostics;
sub bin2cn{
	die "Error:1001:bin2cnn" if chop($_[0]) eq "";
	@hexi = &bin2hex($_[0]);
	while(@hexi){
		$q=shift @hexi if @hexi;#noting
		$temp=&hex2int($q);
		$q=shift @hexi if @hexi;
		$temp=$temp*16+&hex2int($q);
		push @cni,chr($temp);
	}
	join '',@cni
}

sub bin2hex{
	my @binarr=('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111');
	my @hexarr=("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");

	if(length($_[0]) % 4 ){
		my @in = &split4($_[0]);
		while(my $ta=shift @in){
			for (0..15){
				push @re,$hexarr[$_] if ($binarr[$_] eq $ta) ;
			}
		}
		@re
	}else{
		print "Error:1001:bin2hexn";
		exit
	}
}
sub hex2bin{
	my @binarr=('0000','1111');
	my @hexarr=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
	my @in = split //,$_[0];
	while(@in){
		my $tai=shift @in;#noting
		for (0..15){
			push @reo,$binarr[$_] if ($hexarr[$_] eq $tai);
		}
	}
	join '',@reo
}
sub split4{
	my $ini = $_[0];
	push @res,substr($ini,$_,4) for (grep {$_ % 4 == 0 } 0..length($ini));
	@res
}

sub hex2int{
	if ($_[0] =~ /^[ABCDEF]$/){
		ord($_[0])-65+10;
	}elsif($_[0] =~ /^[0123456789]$/){
		ord($_[0])-48;
	}else{
		print "nError: 1001:hex2intn";
		exit
	}
}
#open IN,"<./binaryfile";
#my $tee= <IN>;
#my @sd=&split4($tee);
#print "SS: @sdn";
#print "OO: ".(length($tee) % 8)."n"; 0

#print ord(1)." FF: ".&hex2int(1)."n";

#my $Stee=&bin2cn($tee);
#print "TT: $Steen";

my $ods= "E4B896E7958CEFBC8CE4BDA0E5A5BDE38082";
my $des=&hex2bin($ods);
my $Stea=&bin2cn($des);
print "TT: $Stean";

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读