-1

I have an Integer 138 that i want to covert into an 8 bit signed Integer that will become -118. I have tried unpack, intval and several othe php function but they didn't worked. How should i do this, stuck in this for few days now.

1 Answers1

3

There may be other ways, but a quick look at using pack and unpack - pack with C stores it as an unsigned and the unpack with c gets the signed value back...

echo unpack( 'c', pack('C', 138))[1];

gives

-118
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55