新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php怎么實現(xiàn)轉(zhuǎn)成byte數(shù)組
本文操作環(huán)境:Windows7系統(tǒng)、php7.1版、DELL G3電腦

為企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)站優(yōu)化、營銷型網(wǎng)站建設(shè)、競價托管、品牌運營等營銷獲客服務(wù)。創(chuàng)新互聯(lián)公司擁有網(wǎng)絡(luò)營銷運營團隊,以豐富的互聯(lián)網(wǎng)營銷經(jīng)驗助力企業(yè)精準(zhǔn)獲客,真正落地解決中小企業(yè)營銷獲客難題,做到“讓獲客更簡單”。自創(chuàng)立至今,成功用技術(shù)實力解決了企業(yè)“網(wǎng)站建設(shè)、網(wǎng)絡(luò)品牌塑造、網(wǎng)絡(luò)營銷”三大難題,同時降低了營銷成本,提高了有效客戶轉(zhuǎn)化率,獲得了眾多企業(yè)客戶的高度認可!
php怎么實現(xiàn)轉(zhuǎn)成byte數(shù)組?
php轉(zhuǎn)換byte[]數(shù)據(jù)類型
代碼如下:
= 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 目標(biāo)字符串
* @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 目標(biāo)byte數(shù)組
* @param $val 需要轉(zhuǎn)換的字符串
*/
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 <<= 8;
$val |= $bytes[$position + 2] & 0xff;
$val <<= 8;
$val |= $bytes[$position + 1] & 0xff;
$val <<= 8;
$val |= $bytes[$position] & 0xff;
return $val;
}
/**
* 轉(zhuǎn)換一個shor字符串為byte數(shù)組
* @param $byt 目標(biāo)byte數(shù)組
* @param $val 需要轉(zhuǎn)換的字符串
*/
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 << 8;
$val |= $bytes[$position] & 0xff;
return $val;
}
} 網(wǎng)頁題目:php怎么實現(xiàn)轉(zhuǎn)成byte數(shù)組
新聞來源:http://fisionsoft.com.cn/article/dhgscjg.html


咨詢
建站咨詢
