this code give us this characters ‘-’, ‘-’, ‘-’, ‘+’.
To access the next
character, we need to “shift” the 32-bit integer value by 8 bits to fetch the next character.
This is a simple integer division by 256.
dont know what to do !!
sample data input: 757935403
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main()
{
int a;
cout << "what is your code?" << endl;
cin >> a;
do {
int b = a % 256;
cout <<char(b);
int c = b >> 8;
cout << char (c);
}while (a != 0);
return 0;
}
okay I got that now We need to add a test: if the value of
the decoded character is equal to 0x0A, then we output ‘\n’ (or endl). Otherwise, we
output just the decoded character.
so this is my code
1 2 3 4 5 6 7 8 9 10 11 12
int a;
cout << "what is your code?" << endl;
cin >> a;
do {
int b = a % 256;
if (b == 0x0A){
cout << endl;
}
cout <<char(b);
int c = a/256;
a = c;
}while (a != 0);