开发者

Converting hexadecimal to byte in php

开发者 https://www.devze.com 2023-01-02 07:45 出处:网络
I am very new to PHP I want to create a byte array something like this (in Java): byte array[] = { (byte) 0x9C, (byte) 0xA0};

I am very new to PHP

I want to create a byte array something like this (in Java):

byte array[] = { (byte) 0x9C, (byte) 0xA0};

How do I do it in 开发者_如何学GoPHP? Any syntactical help highly apreciated.


What exactly do you mean by "hexadecimal to byte"? I am going to assume you mean "... to decimal".

The result of 0x3f when output will be automatically converted to a decimal number. In internal calculations, it will be converted automatically if needed - you can do

$myvar = 300 + 0xfa;

without problems.

You can cast a variable to an integer using (int)$varname or (int)value but it doesn't really make sense in your case. A byte is a byte, whether you express its value as 0x3F or 63.

To convert hexadecimal to decimal, there is also hexdec()

Returns the decimal equivalent of the hexadecimal number represented by the hex_string argument. hexdec() converts a hexadecimal string to a decimal number.


How about pack function?

0

精彩评论

暂无评论...
验证码 换一张
取 消