views:

109

answers:

2

I am very new to PHP

I mean I want to create a byte array something like this

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

how to do I do it in PHP any syntactical help highly apreciated.

I mean how to create a byte array in php.

Thanks in advance

+1  A: 

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.

Pekka
+1  A: 

How about pack function?

Aif