0

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 PHP? Any syntactical help highly apreciated.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

How about pack function?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.