How to convert a hexadecimal value into a signed integer in PHP?

后端 未结 2 1322
轻奢々
轻奢々 2021-01-20 04:14

I am trying to convert a hex string into a signed integer.

I am able to easily transfer it into an unsigned value with hexdec() but this does not give a signed value

2条回答
  •  一整个雨季
    2021-01-20 04:43

    Check out this comment via php.net:

    hexdec() returns unsigned integers. For example hexdec("FFFFFFFE") returns 4294967294, not -2. To convert to signed 32-bit integer you may do:

    
    

提交回复
热议问题