PHP string and Byte Conversion example

Source: Internet
Author: User
: This article mainly introduces the PHP string and Byte Conversion examples. if you are interested in the PHP Tutorial, refer to it. Refer: http://www.php230.com/1410667081.html


  > 8 & 0xff); $ byt [2] = ($ val> 16 & 0xff); $ byt [3] = ($ val> 24 & 0xff ); return $ byt ;} /*** read an Integer type data from the specified position in the byte array * @ param $ bytes byte array * @ param $ position specified start position * @ return an Integer type data */publicstaticfunctionbytesToInteger ($ 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 ;} /*** convert a shor string to a byte array * @ param $ byt target byte array * @ param $ val the string to be converted **/publicstaticfunctionshortshorttobytes ($ val) {$ byt = array (); $ byt [0] = ($ val & 0xff); $ byt [1] = ($ val> 8 & 0xff ); return $ byt;}/*** reads data of the Short type from the specified position in the byte array. * @ Param $ bytes byte array * @ param $ position specifies the start position * @ return a Short type data */publicstaticfunctionbytesToShort ($ bytes, $ position) {$ val = 0; $ val = $ bytes [$ position + 1] & 0xFF; $ val = $ val <8; $ val | = $ bytes [$ position] & 0xFF; return $ val ;}}?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.