bit manipulation problems. 2A. Write the definition for a function with one unsi
ID: 3644665 • Letter: B
Question
bit manipulation problems.2A. Write the definition for a function with one unsigned arg n that returns an unsigned. The return value is the result of taking n, flipping bits 0-3 inclusive, turning on bits 4-7 inclusive, turning off bits 8-11 inclusive, and swapping the highest-order byte with the second-highest-order byte. For instance, if the bits of n were
00111010 10101010 10110101 01010111
then the bits of the return value would be
10101010 00111010 10110000 11111000
2B. Write a definition for a function named circularShift with two args: an unsigned n and an int numberBits. In a circular shift, when a bit is shifted out of one end of a number, that same bit is shifted in at the other end. C and C++ don
Explanation / Answer
#include #include #include void main() { int q,t,n,a[20],j,temp; int i=0; int s=0; int tp=0; clrscr(); printf(" enter the num "); scanf("%d",&n); t=n; while(n>0) { a[i]=n%2; i++; n=n/2; } printf(" "); printf("num:%d ",t); printf("number in binary format:"); for(j=i-1;j>=0;j--) { printf("%d",a[j]); } printf(" "); temp=a[i-1]; a[i-1]=a[0]; a[0]=temp; printf("number in binary format wid reversed boundary bits:"); for(j=i-1;j>=0;j--) { printf("%d",a[j]); } printf(" "); q=i-1; while(q>=0) { tp=pow(2,q); s=s+(tp*a[q]); q--; } printf("resulatnt number after reversing boundary bits:%d",s); printf(" "); getch(); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.