Posts

Showing posts with the label bitwise operator

Decimal to Binary Conversion - Bitwise Right shift Operator

It is a number system conversion from decimal value into binary bits is carried out using bitwise >> (right-shift) operator. The Right shift operator moves the bit position of a integer towards right direction. it removes bits from LSB (least significant bit) and add bits (0s) into MSB (most significant bit) and the number bits to remove and to add depends on a operand value next to the right shift operator. For example, the integer variable x=10 , move 1 bit using right-shift binary 8-bits x = 00001010 x = x >> 1 move 1 bit (remove one bit from LSB (0) and add one bit (0) into MSB binary 8-bits x = 00000101 and x's decimal value becomes 5. Decimal to binary conversion using Bitwise Right-shif...

Binary to Decimal Conversion - Bitwise Right shift Operator

It is number system conversion from binary (base -2) to decimal (base -10) is carried out by bitwise >> (right-shift) operator. The Right shift operator moves the bit position of a integer towards right direction. it removes bits from LSB (least significant bit) and add bits (0s) into MSB (least significant bit) and the number bits to remove and to add depends on a operand value next to the right shift operator. For example, the integer variable x=74 , move 2 bit using right-shift operator binary 8-bits of x = 01001010 x = x >> 2 move 2 bit (remove two bits from LSB (10) and add two bits (00) into MSB 2-bits shifted binary 8-bits of x = 00010010 and x's decimal value becomes 18. Binary to decimal conversion using Bitwise Right-shift...

Binary to Decimal conversion -Bitwise Left shift Operator

Binary to decimal conversion using Bitwise Left-shift Operator - algorithm Declaration Input Read char bits[9] Output integer decval Temp var integer n=0,len=0       len = strlen(bits) Loop n=0 to len-1 decval left shift by 1 bits[n] == '1' then decval OR by 1 decval left shift by 1 End Loop Output print,bits Binary to Decimal conversion by Left-shift -C programming code The C programming code converts binary bits into a decimal value by bitwise left-shift operator. The input binary bits are given to the program while it is running and returns a decimal value as conversion result. # include <stdio.h> # include < string .h> int main () { int decval; char bits[9]; int n=0; printf ("\n Bitwise Left-shift Operat or Decimal Conversion"); printf("\n Enter a binary bits :" ); scanf("%s", &bits); ...

Decimal to Binary Conversion - Bitwise Left shift operator

It is a number system conversion from decimal to binary, which is implemented by bitwise left shift operator. The left-shift operator shifts the bits of the decimal value towards left direction. it removes MSB bits and adds bits 0s on LSB of the decimal value. Decimal to Binary Conversion by Left-shift -Manual calculation Given decimal value =19, converts into binary bits. on each iteration, AND (bitwise operation ) with the decimal value and 128, if condition is true, returns 1, otherwise 0, the decimal left shift by 1 , resultant value stored on the same decimal value.  n (decval AND 128) Operation    Decval = decval << by 1 0 bit[0] = (19 AND 128) ? 1:0   38 = 19 <<1 1 bit[1] = (38 AND 128) ? 1:0   76 = 38 <<1 2 bit[2] = (78 AND 128) ? 1:0   152 = 38 <<1 3 bit[3] =...