C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 7)
7.
What will be the output of the program?
#include<stdio.h>
int main()
{
char c=48;
int i, mask=01;
for(i=1; i<=5; i++)
{
printf("%c", c|mask);
mask = mask<<1;
}
return 0;
}
Discussion:
70 comments Page 7 of 7.
Arun said:
1 decade ago
#include<stdio.h>
int main()
{
char c=48;
int i, mask=01;
for(i=1; i<=5; i++)
{
printf("%c", c|mask);
mask = mask<<1;
}
return 0;
}
Please explain above the program.
int main()
{
char c=48;
int i, mask=01;
for(i=1; i<=5; i++)
{
printf("%c", c|mask);
mask = mask<<1;
}
return 0;
}
Please explain above the program.
Kirubhakaran said:
1 decade ago
It is nothing but shifting the binary values to left !! In case if u have a binary number 11001101, after you left shit this binary number by 1 digit, you will have 10011010.. that is, the first digit is removed and a he remaining elements are written and a zero is appended at last...
Yamini said:
1 decade ago
I cant understand that left shift operation "<<"
Can anyone pls explain me n make me clear
Can anyone pls explain me n make me clear
Sowmya said:
1 decade ago
Thanks a lot Sai!! :) :)
Sneha said:
1 decade ago
Thanks sai.
Samatha said:
1 decade ago
Well. Thanku.
Sai said:
1 decade ago
Here mask means unsigned int i.e no negative values....mask 01 means 32 bit value.it is "00000000000000000000000000000001"
c=48 it is written as "00000000000000000000000000110000"
now "or" operation is performed then value becomes 49,
mask=mask<<1 means it shifts 1 to 1-bit before then it becomes "000000000000000000000000000000010".now do o operation with 32digit binary bit of 48.
Now value becomes 50.again mask=mask<<1 "00000100"(last 8bits)similarly do till for loop fails..then we get values as 49,50,52,56,48....the %c converts int to char thatmeans it prints the ASCII values of these nunbers ASCII of 48=0,49=1,50=2......57=9..replace the values u get o/p as 12480......
c=48 it is written as "00000000000000000000000000110000"
now "or" operation is performed then value becomes 49,
mask=mask<<1 means it shifts 1 to 1-bit before then it becomes "000000000000000000000000000000010".now do o operation with 32digit binary bit of 48.
Now value becomes 50.again mask=mask<<1 "00000100"(last 8bits)similarly do till for loop fails..then we get values as 49,50,52,56,48....the %c converts int to char thatmeans it prints the ASCII values of these nunbers ASCII of 48=0,49=1,50=2......57=9..replace the values u get o/p as 12480......
Afsheen said:
1 decade ago
Can anyone please explain this. ?
Ashwin said:
1 decade ago
Explanation. Please?
Chinna said:
2 decades ago
To increment five times in i and multiple by c and i and mask.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers