php兌現(xiàn)java的byte數(shù)組轉(zhuǎn)換
Jun 13, 2016 am 10:54 AM
php實現(xiàn)java的byte數(shù)組轉(zhuǎn)換
由于工作需要,自己寫的一個php實現(xiàn)java的byte數(shù)組轉(zhuǎn)換的類。
/**
?* byte數(shù)組與字符串轉(zhuǎn)化類
?* @author zikie
?* Created on 2011-7-15
?*/
class Bytes {
???
??? /**
???? * 轉(zhuǎn)換一個String字符串為byte數(shù)組
???? * @param $str 需要轉(zhuǎn)換的字符串
???? * @param $bytes 目標byte數(shù)組
???? * @author Zikie
???? */
????
??? public static function getBytes($str) {
??? ??? $len = strlen($str);
??? ??? $bytes = array();
?? ??? ??? for($i=0;$i?? ??? ??? ??? if(ord($str[$i]) >= 128){
?? ??? ??? ??? ??? $byte = ord($str[$i]) - 256;
?? ??? ??? ??? }else{
?? ??? ??? ??? ??? $byte = ord($str[$i]);
?? ??? ??? ??? }
??????? ??? $bytes[] =? $byte ;
??? ??? }
??? ??? return $bytes;
??? }
???
??? /**
???? * 將字節(jié)數(shù)組轉(zhuǎn)化為String類型的數(shù)據(jù)
???? * @param $bytes 字節(jié)數(shù)組
???? * @param $str 目標字符串
???? * @return 一個String類型的數(shù)據(jù)
???? */
????
??? public static function toStr($bytes) {
??? ??? $str = '';
??? ??? foreach($bytes as $ch) {
??????? ??? $str .= chr($ch);
??? ??? }
?? ??? ??? return $str;
??? }
???
??? /**
???? * 轉(zhuǎn)換一個int為byte數(shù)組
???? * @param $byt 目標byte數(shù)組
???? * @param $val 需要轉(zhuǎn)換的字符串
???? * @author Zikie
???? */
???
??? public static function integerToBytes($val) {
??? ??? $byt = array();
??? ??? $byt[0] = ($val & 0xff);
??? ??? $byt[1] = ($val >> 8 & 0xff);
??? ??? $byt[2] = ($val >> 16 & 0xff);
??????? $byt[3] = ($val >> 24 & 0xff);
??????? return $byt;
??? }
???
??? /**
???? * 從字節(jié)數(shù)組中指定的位置讀取一個Integer類型的數(shù)據(jù)
???? * @param $bytes 字節(jié)數(shù)組
???? * @param $position 指定的開始位置
???? * @return 一個Integer類型的數(shù)據(jù)
???? */
????
??? public static function bytesToInteger($bytes, $position) {
??????? $val = 0;
??????? $val = $bytes[$position + 3] & 0xff;
??????? $val ??????? $val |= $bytes[$position + 2] & 0xff;
??????? $val ??????? $val |= $bytes[$position + 1] & 0xff;
??????? $val ??????? $val |= $bytes[$position] & 0xff;
??????? return $val;
??? }
??? /**
???? * 轉(zhuǎn)換一個shor字符串為byte數(shù)組
???? * @param $byt 目標byte數(shù)組
???? * @param $val 需要轉(zhuǎn)換的字符串
???? * @author Zikie
???? */
???
??? public static function shortToBytes($val) {
??? ??? $byt = array();
??? ??? $byt[0] = ($val & 0xff);
??????? $byt[1] = ($val >> 8 & 0xff);
??????? return $byt;
??? }
???
??? /**
???? * 從字節(jié)數(shù)組中指定的位置讀取一個Short類型的數(shù)據(jù)。
???? * @param $bytes 字節(jié)數(shù)組
???? * @param $position 指定的開始位置
???? * @return 一個Short類型的數(shù)據(jù)
???? */
????
??? public static function bytesToShort($bytes, $position) {
??????? $val = 0;
??????? $val = $bytes[$position + 1] & 0xFF;
??????? $val = $val ??????? $val |= $bytes[$position] & 0xFF;
??????? return $val;
??? }
???
}
?>

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

?? ???? ??? ???? ?? ????. ? ??? ???? ? ??? ??? ?? ??? ???? ??? ?????. ?? ??? ????? ? ???? ?? ? ????. 1- ??? ?? ???? ???? ????? ??? ??????. ??? ???? Windows Powershell? ?? ??? ???? ??? ???? ??? ??????. ?? ?????(? ??? ?? ??). ?? ??? ?????. <key>slmgr/ipk<key> ???? ?? ??? ?????? ????? ??? ?????. ?? Powershell(Get-ItemProper)? ?? ??? ?????.

H5?? ?? ??? ???? ???? ?? H5 ????? ??? ?? ?? ? ????? ???? ??? ????. ?? CSS ?? ??? ???? ???. ?? ??? ?? ?? ??, ?? ?? ??, ?? ?? ?? ? ?? ?? ??? ???? ????? ??? ?? ??? ??? ? ????. ?? ???? H5 ???? position ??? ???? ???? ??? ??? ???????.

CSS ???? ?? ??? ?: positionsticky ? flexbox ? ???? ????? ?? ??? ?????. ?? ???? ??? ??? ??? ????? ???? ?? ???? ???? ?? ?? ? ????. CSS ???? ??? ? ??? ???? ? ?????. ? ????? ????? ???? ? ?? CSS ???? ?? ??? ??? positionsticky? flexbox? ???? ???? ?? ??? ?????. 1. ??

Go ???? bytes ???? ??? ??? ???? ?? ????? Split() ???? ?? ??? ???? ?? ?????. ??? Split() ???? ???? ?? "???? ??: bytes.Split" ??? ??? ? ????. ? ??? ????? Go ??? ???? ??? ??? ?? ?????? ???? ?????. ? ????? ? ??? ???? ? ?? ??? ?????. ?? 1: ??? ?? Go ??? ????????.

1???? 8??? ????. ??? ??? "???"(Byte) ??? ?????, ??? ??? ??? "??"(bit) ??? ?????, 1??? 0 ?? 1(?, ????)? ????, 8??(bit)?? ) Byte? ??? ?? ?? ????? "1Byte=8bit"???.

H5??? position ??? ???? CSS? ?? ??? ?? ??? ??? ? ????. 1. ?? ?? ??, ??? "style="position:relative;"; 2. ?? ?? ??, ??? "style="position: ??;" "; 3. ?? ?? ??, ??? "style="position:fixed;" ????.

HTML ??? div? ???? ??: 1. "div{position:fixed;}" ??? ???? ?? ??? ???? ???? ?? ???? div ??? ?????. 2. ????? ??? ?????. 0 ??? ??? div? ????? ????? ??? "div{bottom:0;}"???.

Golang ??????? ???, ? ? ??? ??? ?? ????? ???? ??? ?????. ??? ? ?? ???? ?? ??? ??? ???? ? ??? ??? ???. ??? ??? ??? ??? ? ????? ?? ???? ??, ?? ???? ?? ?? ??? ???? ???. ? ????? ??? ??? ??? ??? ? ? ???? ????? ??? ???? ??? ? ??? ?? ?? Golang ??? ???, ? ? ??? ?? ?? ??? ?????.
