# Bitwise operator

Page 1 of 1

## 4 Replies - 1033 Views - Last Post: 02 September 2009 - 02:20 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=123576&amp;s=0a5046390308116af1bac0915358b02d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hd_pulse

Reputation: 0
• Posts: 36
• Joined: 31-August 09

# Bitwise operator

Posted 02 September 2009 - 12:59 PM

```#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=43,b=76;
printf("%d \n",a & b);
printf("%d \n",a && b);

printf("%d \n",a<<2);
getch();
}

```

when I compile above program i get such outputs...
8
1
172

Plz help me to know how 'bitwise operators' are working here????????

thanks

Is This A Good Question/Topic? 0

Reputation:

## Re: Bitwise operator

Posted 02 September 2009 - 01:28 PM

What is there to explain? These are straightforward bitwise operations (althought the second one is just a boolean comparison),

### #3 Novast11

Reputation: 1
• Posts: 30
• Joined: 12-June 09

## Re: Bitwise operator

Posted 02 September 2009 - 01:36 PM

hd_pulse, on 2 Sep, 2009 - 11:59 AM, said:

```#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=43,b=76;
printf("%d \n",a & b);
printf("%d \n",a && b);

printf("%d \n",a<<2);
getch();
}

```

when I compile above program i get such outputs...
8
1
172

Plz help me to know how 'bitwise operators' are working here????????

thanks

These are binary operations.

43 in binary = 0010 1011
76 in Binary = 0100 1100

For the first print:
printf("%d \n",a & b );

0010 1011
& 0100 1100
-----------------
0000 1000 = 8

### #4 KYA

• yay verily

Reputation: 3155
• Posts: 19,200
• Joined: 14-September 07

## Re: Bitwise operator

Posted 02 September 2009 - 02:06 PM

There's a few decent tutorials here in the C++ section of </DIC> (here and here)

### #5 debjit625

• D.I.C Regular

Reputation: 51
• Posts: 446
• Joined: 06-September 08

## Re: Bitwise operator

Posted 02 September 2009 - 02:20 PM

And
```a<<2;

```

This "<<" is called binary left-shift operator it shift the position of the bits from right to left that is in you case 'a' is an int i.e. 32bits but i am assumming it 16bits to make it simple
so 'a' = 43 in binary its 0000000000101011 = 43
now shift it once 0000000001010110 = 86 (43*2)
now shift it again 0000000010101100 = 172 (86*2)
Look at the position of the bits
this just multiply the number by 2 and the number of times we ask it to do ,in your case it was 2 times (a<<2).

And their are many tutorial for these ,their are not too many binary operators in C++ but their are many out comes by those operators and this is logic.

Good luck

This post has been edited by debjit625: 02 September 2009 - 02:23 PM