国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial php兌現(xiàn)java的byte數(shù)組轉(zhuǎn)換

php兌現(xiàn)java的byte數(shù)組轉(zhuǎn)換

Jun 13, 2016 am 10:54 AM
byte bytes param position val

php實(shí)現(xiàn)java的byte數(shù)組轉(zhuǎn)換

由于工作需要,自己寫的一個(gè)php實(shí)現(xiàn)java的byte數(shù)組轉(zhuǎn)換的類。



/**
?* byte數(shù)組與字符串轉(zhuǎn)化類
?* @author zikie
?* Created on 2011-7-15
?*/

class Bytes {
???
??? /**
???? * 轉(zhuǎn)換一個(gè)String字符串為byte數(shù)組
???? * @param $str 需要轉(zhuǎn)換的字符串
???? * @param $bytes 目標(biāo)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 目標(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)換的字符串
???? * @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ù)組中指定的位置讀取一個(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 ??????? $val |= $bytes[$position + 2] & 0xff;
??????? $val ??????? $val |= $bytes[$position + 1] & 0xff;
??????? $val ??????? $val |= $bytes[$position] & 0xff;
??????? return $val;
??? }

??? /**
???? * 轉(zhuǎn)換一個(gè)shor字符串為byte數(shù)組
???? * @param $byt 目標(biāo)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ù)組中指定的位置讀取一個(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 ??????? $val |= $bytes[$position] & 0xFF;
??????? return $val;
??? }
???
}
?>

1 樓 tron.lu 2012-02-06??
3des 加密的時(shí)候用嗎?

2 樓 heaven__18 2012-03-13??
在很多地方都能用的到。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

HWID V 2.2 manual activation methods and tutorials HWID V 2.2 manual activation methods and tutorials Oct 20, 2023 pm 07:17 PM

This is for users who want to perform manual activation. If you need help with a tool for you to do this, then check here. We can divide the manual activation process into two parts. 1- From the ready-made batch file make sure the internet is enabled. Open Windows Powershell as administrator and enter the following to list the commands in the order they are given. Enter the key, (replace with the key from the list above) Use the following command <key>slmgr/ipk<key> Download the universal ticket from here and extract the downloaded file. Now enter the following code in Powershell (Get-ItemProper

Flexible application skills of position attribute in H5 Flexible application skills of position attribute in H5 Dec 27, 2023 pm 01:05 PM

How to flexibly use the position attribute in H5. In H5 development, the positioning and layout of elements are often involved. At this time, the CSS position property will come into play. The position attribute can control the positioning of elements on the page, including relative positioning, absolute positioning, fixed positioning and sticky positioning. This article will introduce in detail how to flexibly use the position attribute in H5 development.

CSS layout property optimization tips: position sticky and flexbox CSS layout property optimization tips: position sticky and flexbox Oct 20, 2023 pm 03:15 PM

CSS layout attribute optimization tips: positionsticky and flexbox In web development, layout is a very important aspect. A good layout structure can improve the user experience and make the page more beautiful and easy to navigate. CSS layout properties are the key to achieving this goal. In this article, I will introduce two commonly used CSS layout property optimization techniques: positionsticky and flexbox, and provide specific code examples. 1. positions

How to solve 'undefined: bytes.Split' error in golang? How to solve 'undefined: bytes.Split' error in golang? Jun 25, 2023 pm 02:02 PM

In the Go language, the bytes package is a package for manipulating byte types, and it contains many useful methods, such as the Split() method. However, when using the Split() method, you may encounter an "undefined: bytes.Split" error. This error is usually caused by incompatible Go versions or lack of necessary dependent libraries. This article will introduce some methods to solve this error. Method 1: Upgrade the Go version as follows

1byte equals how many bits 1byte equals how many bits Mar 19, 2021 pm 02:52 PM

1byte equals 8bit. Data storage is in "byte" (Byte) as the unit, and data transmission is mostly in "bit" (bit) as the unit. One bit represents a 0 or 1 (that is, binary), and every 8 bits (bit) form a Byte is the smallest unit of information; therefore, "1Byte=8bit".

How to use position in h5 How to use position in h5 Dec 26, 2023 pm 01:39 PM

In H5, you can use the position attribute to control the positioning of elements through CSS: 1. Relative positioning, the syntax is "style="position: relative;"; 2. Absolute positioning, the syntax is "style="position: absolute;" "; 3. Fixed positioning, the syntax is "style="position: fixed;" and so on.

How to put div at the bottom in html How to put div at the bottom in html Mar 02, 2021 pm 05:44 PM

How to place a div at the bottom of HTML: 1. Use the position attribute to position the div tag relative to the browser window, with the syntax "div{position:fixed;}"; 2. Set the distance to the bottom to 0 to permanently place the div at At the bottom of the page, the syntax is "div{bottom:0;}".

Golang function byte, rune and string type conversion skills Golang function byte, rune and string type conversion skills May 17, 2023 am 08:21 AM

In Golang programming, byte, rune and string types are very basic and common data types. They play an important role in processing data operations such as strings and file streams. When performing these data operations, we usually need to convert them to each other, which requires mastering some conversion skills. This article will introduce the byte, rune and string type conversion techniques of Golang functions, aiming to help readers better understand these data types and be able to apply them skillfully in programming practice.

See all articles