Objective: Become familiar with loop structures Become familiar bitwise operatio
ID: 3628347 • Letter: O
Question
Objective:Become familiar with loop structures
Become familiar bitwise operations
Become familiar with storing mechanism of numbers
Program to be written in C++
The program will ask for two numbers; one integer and one unsigend integer.
The porgram will produce the binary patterns that are stored in each of the memory locations corresponding to the int and unsigned int data.
Notes:
This program does not just convert a number into binary. It probes the memory location one bit at a time.
You will need to use a Mask, logical bit, and shift operators.
Sample screen:
Enter an int, unsigned int: 0 0
00000000000000000000000000000000
00000000000000000000000000000000
Enter an int, unsigned int: 1 1
00000000000000000000000000000001
00000000000000000000000000000001
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int a;
unsigned int b;
cin>>a;
cin>>b;
for(int i=0; i<32; i++)
{
cout << ( a & (1 << i));
}
cout << endl;
for(int i=0; i<32; i++)
{
cout << ( b & (1 << i));
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.