0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JSビット演算子

Last updated at Posted at 2025-04-08
let a = 5;  // 0101(二進数)
let b = 3;  // 0011(二進数)

let result = a & b; // 0101 & 0011 = 0001(二進数)
console.log(result); // 1

これは5と3を二進数にしたとき、1桁目がどちらも1だったから0001(二進数)を返し、それは1だから1を返すということで

let a = 7;  // 0111(二進数)
let b = 5;  // 0101(二進数)

let result = a & b; // 0111 & 0101 = 0101(二進数)
console.log(result); // 5

は一致してるのが3桁目と1桁目なので、 0101(二進数)を返し、それは5なので結果が5になるということ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?