+ 1

Explain the reason using logic for such an output.

https://code.sololearn.com/cF8Qox9h1qJN/?ref=app

12th Aug 2019, 5:38 PM
Brutual bro
Brutual bro - avatar
2 Antworten
+ 8
Brutual bro the code has integer I which is initialise with 32 and for loop is executed with the right shift operator and shifting is perform right side by 1 bit for that first number i is converted into bits. 32 = 100000 And this loop is execute till the every eight shift bit has an value. By right shift the value will be change into 32,16,8,4,2,1,0 this way loop run 6 times so six time the statement is printed as output #include<stdio.h> int main() { int a = 32; printf("\nNumber is Shifted By 1 Bit : %d",a >> 1); printf("\nNumber is Shifted By 2 Bits : %d",a >> 2); printf("\nNumber is Shifted By 3 Bits : %d",a >> 3); printf("\nNumber is Shifted By 4 Bits : %d",a >> 4); printf("\nNumber is Shifted By 5 Bits : %d",a >> 5); return(0); }
12th Aug 2019, 6:31 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Think of right shifting as dividing by 2.
12th Aug 2019, 11:47 PM
Sonic
Sonic - avatar