9.Operators in C++ part - 4 (Bit-wise Operators)

preview_player
Показать описание
Bitwise operators are special types of operators that are used in programming the processor. In processor, mathematical operations like: addition, subtraction, addition and division are done using the bitwise operators which makes processing faster and saves power.

Bitwise AND operator
=================
The output of logical AND is 1 if both the corresponding bits of operand is 1. If either of bit is 0 or both bits are 0, the output will be 0. It is a binary operator(works on two operands) and indicated in C programming by & symbol. Let us suppose the bitwise AND operation of two integers 12 and 25.As, every bitwise operator works on each bit of data. The corresponding bits of two inputs are check and if both bits are 1 then only the output will be 1. In this case, both bits are 1 at only one position,i.e, fourth position from the right, hence the output bit of that position is 1 and all other bits are 0.

Bitwise OR operator
================
The output of bitwise OR is 1 if either of the bit is 1 or both the bits are 1. In C Programming, bitwise OR operator is denoted by |.

Bitwise XOR(exclusive OR) operator
============================
The output of bitwise XOR operator is 1 if the corresponding bits of two operators are opposite(i.e., To get corresponding output bit 1; if corresponding bit of first operand is 0 then, corresponding bit of second operand should be 1 and vice-versa.). It is denoted by ^.

Bitwise compliment operator
======================
Bitwise compliment operator is an unary operator(works on one operand only). It changes the corresponding bit of the operand to opposite bit,i.e., 0 to 1 and 1 to 0. It is denoted by ~.Output of ~35 shown by compiler won't be 220, instead it shows -36. For any integer n, bitwise complement of n will be -(n+1). To understand this, you should understand the concept of 2's complement.

bitwise complement of N= ~N (represented in 2's complement form) 2'complement of ~N= -(~(~N)+1) = -(N+1)
Рекомендации по теме
Комментарии
Автор

awesome lectures, thanks for your videos sir.

r.janasrirega
Автор

Hi, yo know why  10 ^ 23 =  -2147483648 in language C? Thanks you

MsPAL
join shbcf.ru