新聞中心
本文操作環(huán)境:Windows7系統(tǒng)、php7.1版、DELL G3電腦

為企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)站優(yōu)化、營(yíng)銷型網(wǎng)站建設(shè)、競(jìng)價(jià)托管、品牌運(yùn)營(yíng)等營(yíng)銷獲客服務(wù)。創(chuàng)新互聯(lián)公司擁有網(wǎng)絡(luò)營(yíng)銷運(yùn)營(yíng)團(tuán)隊(duì),以豐富的互聯(lián)網(wǎng)營(yíng)銷經(jīng)驗(yàn)助力企業(yè)精準(zhǔn)獲客,真正落地解決中小企業(yè)營(yíng)銷獲客難題,做到“讓獲客更簡(jiǎn)單”。自創(chuàng)立至今,成功用技術(shù)實(shí)力解決了企業(yè)“網(wǎng)站建設(shè)、網(wǎng)絡(luò)品牌塑造、網(wǎng)絡(luò)營(yíng)銷”三大難題,同時(shí)降低了營(yíng)銷成本,提高了有效客戶轉(zhuǎn)化率,獲得了眾多企業(yè)客戶的高度認(rèn)可!
php怎么實(shí)現(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 一個(gè)string類型的數(shù)據(jù)
*/
public static function tostr($bytes) {
$str = '';
foreach($bytes as $ch) {
$str .= chr($ch);
}
return $str;
}
/**
* 轉(zhuǎn)換一個(gè)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ù)組中指定的位置讀取一個(gè)integer類型的數(shù)據(jù)
* @param $bytes 字節(jié)數(shù)組
* @param $position 指定的開始位置
* @return 一個(gè)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)換一個(gè)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ù)組中指定的位置讀取一個(gè)short類型的數(shù)據(jù)。
* @param $bytes 字節(jié)數(shù)組
* @param $position 指定的開始位置
* @return 一個(gè)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;
}
} 分享文章:php怎么實(shí)現(xiàn)轉(zhuǎn)成byte數(shù)組
文章URL:http://www.dlmjj.cn/article/dhgscjg.html


咨詢
建站咨詢
