2

I was playing with JavaScript's bit manipulation where i tried "and operation" with various numbers and every time got binary result but for few numbers i am always getting weird decimal number.

10100 & 1000 = 864

864 why?

Vikas
  • 41
  • 5

1 Answers1

2

&& is logical operator, & is bitwise logical operator

decimal | binary
 ------------------------
  10100 = 10011101110100
   1000 =     1111101000
        &
    864 =     1101100000

As @Andrey mention, if you want to force binary notation use 0b prefix 0b10100 and 0b1000

ponury-kostek
  • 6,780
  • 4
  • 17
  • 26