File tree 1 file changed +12
-7
lines changed
1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -700,10 +700,14 @@ public static function binToHex($bin_string)
700
700
$ hex = '' ;
701
701
$ len = self ::ourStrlen ($ bin_string );
702
702
for ($ i = 0 ; $ i < $ len ; ++$ i ) {
703
- $ c = \ord ($ bin_string [$ i ]) & 0xf ;
704
- $ b = \ord ($ bin_string [$ i ]) >> 4 ;
705
- $ hex .= \chr (87 + $ b + ((($ b - 10 ) >> 8 ) & ~38 ));
706
- $ hex .= \chr (87 + $ c + ((($ c - 10 ) >> 8 ) & ~38 ));
703
+ $ chunk = unpack ('C ' , self ::ourSubstr ($ bin_string , $ i , 1 ));
704
+ $ c = $ chunk [1 ] & 0xf ;
705
+ $ b = $ chunk [1 ] >> 4 ;
706
+ $ hex .= pack (
707
+ 'CC ' ,
708
+ (87 + $ b + ((($ b - 10 ) >> 8 ) & ~38 )),
709
+ (87 + $ c + ((($ c - 10 ) >> 8 ) & ~38 ))
710
+ );
707
711
}
708
712
return $ hex ;
709
713
}
@@ -722,8 +726,10 @@ public static function hexToBin($hex_string)
722
726
$ hex_len = self ::ourStrlen ($ hex_string );
723
727
$ state = 0 ;
724
728
729
+ $ chunk = \unpack ('C* ' , $ hex_string );
725
730
while ($ hex_pos < $ hex_len ) {
726
- $ c = \ord ($ hex_string [$ hex_pos ]);
731
+ ++$ hex_pos ;
732
+ $ c = $ chunk [$ hex_pos ];
727
733
$ c_num = $ c ^ 48 ;
728
734
$ c_num0 = ($ c_num - 10 ) >> 8 ;
729
735
$ c_alpha = ($ c & ~32 ) - 55 ;
@@ -739,8 +745,7 @@ public static function hexToBin($hex_string)
739
745
} else {
740
746
$ bin .= \chr ($ c_acc | $ c_val );
741
747
}
742
- $ state = $ state ? 0 : 1 ;
743
- ++$ hex_pos ;
748
+ $ state ^= 1 ;
744
749
}
745
750
return $ bin ;
746
751
}
You can’t perform that action at this time.
0 commit comments