AND 비트연산(&)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

AND 비트 연산자(&)는 두 개의 피연산자의 각 자리마다 대응하는 비트가 모두 1일 경우 1을 반환합니다.

시도해보기

const a = 5; // 00000000000000000000000000000101
const b = 3; // 00000000000000000000000000000011

console.log(a & b); // 00000000000000000000000000000001
// Expected output: 1

구문

js
a & b;

설명

피연산자는 32비트 정수로 변환되며 일련의 비트(0과 1)로 표현됩니다. 32비트 이상인 숫자는 최상위 비트가 삭제됩니다. 예를 들어 32비트 이상인 다음 정수는 32비트 정수로 변환됩니다.

js
Before: 11100110111110100000000000000110000000000001;
After: 10100000000000000110000000000001;

첫 번째 피연산자의 각 비트는 두 번째 피연산자의 해당 비트(첫 번째 비트첫 번째 비트, 두 번째 비트두 번째 비트 등등)와 쌍을 이룹니다.

연산자가 각 비트의 쌍에 적용되며, 결과는 완성된 비트 연산된 값입니다.

AND 연산에 대한 진리표는 다음과 같습니다:

a b a AND b
0 0 0
0 1 0
1 0 0
1 1 1
js
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
    14 (base 10) = 00000000000000000000000000001110 (base 2)
                   --------------------------------
14 & 9 (base 10) = 00000000000000000000000000001000 (base 2) = 8 (base 10)

어떤 수 x0을 AND 비트 연산한 결과는 0가 됩니다.

예제

AND 비트 연산 사용하기

js
// 5: 00000000000000000000000000000101
// 2: 00000000000000000000000000000010
5 & 2; // 0

명세

Specification
ECMAScript® 2025 Language Specification
# prod-BitwiseANDExpression

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Bitwise AND (a & b)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

같이 보기