Posts

C – Bit wise Operators

Image
C – Bit wise Operators BIT WISE OPERATORS IN C : These operators are used to perform bit operations. Decimal values are converted into binary values which are the sequence of bits and bit wise operators work on these bits. Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise NOT), ^ (XOR), << (left shift) and >> (right shift). TRUTH TABLE FOR BIT WISE OPERATION  &  BIT WISE OPERATORS: BELOW ARE THE BIT-WISE OPERATORS AND THEIR NAME IN C LANGUAGE. & – Bitwise AND | – Bitwise OR ~ – Bitwise NOT ^ – XOR << – Left Shift >> – Right Shift Consider x=40 and y=80. Binary form of these values are given below. x = 00101000 y=  01010000 All bit wise operations for x and y are given below. x&y = 00000000 (binary) = 0 (decimal) x|y = 01111000 (binary) = 120 (decimal) ~x = 11111111111111111111111111 11111111111111111111111111111111010111 = -41 (de...

C – Increment/decrement Operators

C – Increment/decrement Operators Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs. Syntax: Increment operator: ++var_name; (or) var_name++; Decrement operator: – -var_name; (or) var_name – -; Example: Increment operator :  ++ i ;    i ++ ; Decrement operator :  – – i ;   i – – ; EXAMPLE PROGRAM  FOR INCREMENT OPERATORS IN C : In this program, value of “i” is incremented one by one from 1 up to 9 using “i++” operator and output is displayed as “1 2 3 4 5 6 7 8 9”. C 1 2 3 4 5 6 7 8 9 10 11 12 //Example for increment operators #include <stdio.h> int main ( ) {      int i = 1 ;      while ( i < 10 )      {          pri...