Wednesday 15 September 2010

integer - Increment hex value (little endian?) in PHP -



integer - Increment hex value (little endian?) in PHP -

in incoming udp packet have hex value b70500. sequence number (1463). need increment value before sending server in same format (b80500).

how can i, in php, increment value one?

using code suggested here able convert hex value integer , increment one:

$original_hex = 'b70500'; // 1463 $original_int = unpack("h*", strrev(pack("h*", $original_hex))); // 0005b7 $incremented_int = hexdec($original_int[1]) + 1; // 1464 $incremented_hex = ? // expected result: b80500

... have no thought how convert hex. perhaps there more efficient method?

hexdec() , dechex(). not have unpack value.

$incremented = dechex(hexdec('b70500') + 1);

php integer hex increment

No comments:

Post a Comment