This blog is under construction

Monday 30 December 2013

Bitwise shift operators with example

There are two types of shift operators.  They are
1. Left shift operator (<<)
2. Right shift operator(>>)

Left shift operator:
It is used to shift the bits of the first operand to left by the number of bit places the second operand specifies.

Example: 2 << 4
Binary value of 2 is 00000010
00000010 << 4 is 00100000
Decimal value of 00100000 is 32

Right shift operator:
It is used to shift the bits of the first operand to right by the number of bit places the second operand specifies.

Example: 32 >> 4
Binary value of 32 is 00100000
00100000 >> 4 is 00000010
Decimal value of 00000010 is 2

Example C program on bitwise shift operators
 
  #include <stdio.h>
  int main() {
        int x = 2, y = 4, res;
        res = x << y;  // left shift x by y
        printf("%d << %d is %d\n", x, y, res);
        x = res;
        res = x >> y;  // right shift x by y
        printf("%d >> %d is %d\n", x, y, res);
        return 0;
  }


  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  02 << 4 is 32
  32 >> 4 is 2



2 comments:

  1. Hello Everyone !

    USA SSN Leads/Dead Fullz available, along with Driving License/ID Number with good connectivity.

    All SSN's are Tested & Verified.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If you buy in bulk, will give you discount
    *Sampling is just for serious buyers

    ->Hope for the long term business
    ->You can buy for your specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ReplyDelete
  2. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete