0

i'm new here and i have a question that i couldn't find an answer to:

<?php 
$val1 = 25; 
$val2 = 15; 
echo ($value & $value1); // output : 9
?>

Can anyone explain step by step how this returned 9 ?

Thank you

Barry
  • 43
  • 1
  • 5

2 Answers2

2

& is an AND operator. It's sort of like &&, but applies to binary numbers.

25 = 00011001

15 = 00001111

.....& 00001001 which in binary is 9

Basically, only the bits that are 1 in both the first and second number remain 1, the rest turn to 0.

Martin
  • 22,212
  • 11
  • 70
  • 132
Cârnăciov
  • 1,169
  • 1
  • 12
  • 24
1

& operator works with binary representation of a number:

25 is 00011001 15 is 00001111

00011001
       &
00001111
--------
00001001

Which is 9 in decimal.

u_mulder
  • 54,101
  • 5
  • 48
  • 64