PHP Hex to Integer

I am integrating a PHP application with an API that uses permissions in the form 0x00000008, 0x20000000etc., where each of them represents a given permission. Their API returned an integer. In PHP, how do I interpret something like 0x20000000an integer so that I can use bitwise operators?

Another developer told me that he considers these numbers to be hexadecimal annotation, but googling that in PHP I find limited results. What numbers are these and how can I take a set of permissions integer, and using bitwise operators to determine if the user can0x00000008 .

+4
source share
2 answers

php, , C, php ( ).

<?php
echo 0xDEADBEEF; // outputs 3735928559

: https://3v4l.org/g1ggf

: http://php.net/manual/en/language.types.integer.php#language.types.integer.syntax

, , ( , , 64- , , , phpinfo() ).

echo 0x00000001<<3; // 1*2*2*2, outputs 8

: https://3v4l.org/AKv7H

: http://php.net/manual/en/language.operators.bitwise.php

@iainn @SaltyPotato , API, , , , . , hexdec, .

: http://php.net/manual/en/function.hexdec.php

+3

API php,

echo hexdec('0x00000008');

8

.

+2

Source: https://habr.com/ru/post/1686967/


All Articles