I am using C and I am a beginner.
I have to write a function that manipulates bits.
Write a main program to test the function.
Experiment with Sleep and Beep functions to play music.
Write a function with the following function prototype that rotates the bits in a int by one bit tot the left each time and returns the rotated value to the caller/
Write a main program to display the binary data each time it is rotated and generate a console output. Use Sleep() to delay the printing of each bit and Beep() to make a sound each time a bit is printed.
So basically i have to scan in a number from the keyboard, change it into binary, then have the 1 move to the left. Each time the 1 moves a tune has to come on.
this is what our teacher gave us just as a starter
void DisplayBits(int iValue)
{
int iBitCount; //bit counter
int iMask = 1 << 31; //bit mask
printf("%11d = ", iValue);
for(iBitCount = 1; iBitCount <= 32; iBitCount++)
{
if(iValue & iMask)
putchar('1'); //endif
else
putchar('0'); //endelse
iValue <<= 1; //shift value 1 bit to left
if(iBitCount % 8 == 0)
putchar(' '); //endif
} //endfor
putchar('\n');
} //endDisplayBits
Thank you very much
I have to write a function that manipulates bits.
Write a main program to test the function.
Experiment with Sleep and Beep functions to play music.
Write a function with the following function prototype that rotates the bits in a int by one bit tot the left each time and returns the rotated value to the caller/
Write a main program to display the binary data each time it is rotated and generate a console output. Use Sleep() to delay the printing of each bit and Beep() to make a sound each time a bit is printed.
So basically i have to scan in a number from the keyboard, change it into binary, then have the 1 move to the left. Each time the 1 moves a tune has to come on.
this is what our teacher gave us just as a starter
void DisplayBits(int iValue)
{
int iBitCount; //bit counter
int iMask = 1 << 31; //bit mask
printf("%11d = ", iValue);
for(iBitCount = 1; iBitCount <= 32; iBitCount++)
{
if(iValue & iMask)
putchar('1'); //endif
else
putchar('0'); //endelse
iValue <<= 1; //shift value 1 bit to left
if(iBitCount % 8 == 0)
putchar(' '); //endif
} //endfor
putchar('\n');
} //endDisplayBits
Thank you very much
