not a user input

closed account (4w7X92yv)
Hello

I have the following problem.
I wrote the code, but it works whit a user input.
I want to change it so the user input is gone and only the programmer can give a value to the int.
Now it converts the user inputted number from HEX to BIN, and i want to give a value to hex and hex2 (in the program like: int hex = ff) so he calculated the BINARY value of them

Best Regards
Joriek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

int main()
{
int hex = 0;
int Number = 0;
int hex2 = 0;
int Number2 = 0;

std::cin >> std::hex >> hex;
std::cin >> std::hex >> hex2;


Number = hex;

bool Binary[sizeof(Number) * CHAR_BIT];
for(unsigned int i = 0; i < sizeof(Number) * CHAR_BIT; i++)
Binary[(sizeof(Number) * CHAR_BIT - 1) - i] = Number & (1 << i);
for(unsigned int i = 0; i < sizeof(Number) * CHAR_BIT; i++)

std::cout << Binary[i];
std::cout << std::endl; 

Number2 = hex2;

bool Binary2[sizeof(Number2) * CHAR_BIT];
for(unsigned int i2 = 0; i2 < sizeof(Number2) * CHAR_BIT; i2++)
Binary2[(sizeof(Number2) * CHAR_BIT - 1) - i2] = Number2 & (1 << i2);
for(unsigned int i2 = 0; i2 < sizeof(Number2) * CHAR_BIT; i2++)

std::cout << Binary2[i2];
std::cout << std::endl; 


system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.