Integer in memory

Hello. I need help with a little problem that I have. I need to write a programm like this :
Enter your number : 5
Your number in memory: 00000000000000000000000000000101

Can anyone help me with the segment with the number in memory code ?

Thanks.
Last edited on
closed account (48T7M4Gy)
I need to write a programm (sic) like this :
Enter your number : 5


Can u do that bit?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
	int number, temp, a[4];
	cout << "Enter the number less than 16";
	cin >> number;
	if (number < 0 || number > 15) {
		cout << "Please enter valid number";
		exit;
	}
	for (int i = 3; i >= 0; --i) {
		temp = number / 2;
		int tmp = number % 2;
		a[i] = tmp;
		number = temp;
	}
	for (int j = 0; j < 4; ++j) {
		 cout << a[j];
	}
	return 0;
}


Is this what you wanted?
Last edited on
Topic archived. No new replies allowed.