数值循环位移代码
用PHP实现了数值循环左移功能,
源码
<?php
echo '<br>';
$ebx = 0x1;
$num = 0x10;
bins($ebx,$num);
function bins($a,$num){
$arr = array();
//将数值转换为二进制
$b = 0;
for($i=32;$i>0;$i--){
$arr[$b] = ($a & 1 << $b) == 0 ? 0 : 1;
$b++;
}
//ROL 循环左移,且移出的位赋值给 CF
$cf = 0;
$arr1 = array();
$arr2 = array();
$a = '';
$arr1 = $arr;
for($i=0;$i<$num;$i++){
for($j=count($arr1)-1;$j>0;$j--){
$arr2[$j] = $arr1[$j-1];
}
$arr2[0] = $arr1[31];//cf
$cf = $arr2[0];
for($k=31;$k>0;$k--){
echo ' '.$arr2[$k-1];
$b++;
}
echo ' CF='.$cf;
//二进制转换成10进制
$c = 0;
for($l=0;$l<32;$l++){
$c = $c + ($arr2[$l] << $l);
}
echo ' '.$c.' 0x'.dechex($c).'<br>';
$arr1 = $arr2;
$j = 0;
$c = 0;
}
}
echo '<br>';
源码
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 CF=0 2 0x2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 CF=0 4 0x4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 CF=0 8 0x8
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 CF=0 16 0x10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 CF=0 32 0x20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 CF=0 64 0x40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 CF=0 128 0x80
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 CF=0 256 0x100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 CF=0 512 0x200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 CF=0 1024 0x400
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 CF=0 2048 0x800
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 CF=0 4096 0x1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 CF=0 8192 0x2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CF=0 16384 0x4000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CF=0 32768 0x8000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CF=0 65536 0x10000
如果你对这篇文章有什么改进意见,请点击这里告诉我。
热门
随机
御坂网络 - 任何足夠先進的技術,初看皆與魔法無異!