Chinaunix首页 | 论坛 | 博客
  • 博客访问: 28953
  • 博文数量: 10
  • 博客积分: 370
  • 博客等级: 一等列兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-10 22:19
文章分类

全部博文(10)

文章存档

2011年(1)

2010年(7)

2009年(2)

我的朋友

分类:

2010-08-09 18:38:23

sub ChangeByte
{
my $file=shift();
my $Byte=shift();
my $value=shift();
open(FH,"+<$file") or die "File not exist \n";
binmode FH;
seek (FH,$Byte,0);
print (FH pack("H*",$value));
close(FH);
}

sub ChangeBit
{
my $file=shift();
my $Byte=shift();
my $Bit=shift();
#my $value1=shift(); 

open(FH,"+<$file") or die "File not exist \n";
binmode FH;
my $charb;
seek (FH,$Byte,0);
read(FH,$charb,1);
my $Bit2;
$Bit2=7-$Bit;
($charb)=unpack("B*",$charb);
       #print "the Byte is $charb";
my $chara=substr($charb,0,$Bit2);
my $value=substr($charb,$Bit2,1);
my $value1;
 
if ($value eq "1")
{
$value1="0";
}
else
{
$value1="1";
}
my $charc=substr($charb,$Bit2+1,$Bit);
$charb=$chara.$value1.$charc;
 
seek (FH,$Byte,0);
print (FH pack("B*",$charb));
close(FH);
}
阅读(2693) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~