I have a number 00101 when I print out this number (or using it for my purpose) I got 65, I've tried intval() but it also returns 65. Can anyone explain to me why? And what is the easiest way to get 00101, or 101?
Asked
Active
Viewed 90 times
-2
Luu Hoang Bac
- 433
- 6
- 17
-
3can we see the actual code? – treyBake Oct 04 '19 at 10:07
-
1Because its octal value. Read this https://www.php.net/manual/en/language.types.integer.php – Rahul Oct 04 '19 at 10:07
-
1Possible duplicate of [Convert string to binary then back again using PHP](https://stackoverflow.com/questions/6382738/convert-string-to-binary-then-back-again-using-php) – freeek Oct 04 '19 at 10:11
-
@Rahul Thanks, so do you know what is the easiest way to get `00101`, or `101` in number? – Luu Hoang Bac Oct 04 '19 at 10:12
-
Code you tried ? – nice_dev Oct 04 '19 at 10:23
2 Answers
0
I would say you are using an invalid type of number, there is bits type (see the list of types in https://www.php.net/manual/en/langref.php)
if you run the following
$a = array(10101, 11100, 11010, 00101); var_dump($a);
you will see that PHP convert your number to int 65
so maybe you want to use strings?
lunarnet76
- 666
- 5
- 8
0
You will get 101 from string '00101' when passing to intval function. However an integer number does not have start with leading 0; PHP does not get it as decimal number.
infomasud
- 2,263
- 1
- 18
- 12