Hello everyone,
I am using the following code to transfer bytes to binary:
char szByte[9];
int i;
BYTE bArr[400];
// Read Bytes into array here
for (i=0; i < 400; i++)
{
cout << "Byte #" << itoa(i, szByte, 10) << ": ";
cout << itoa(bArr, szByte, 2) << endl;
}
Problem with the above code, eventhough it rocks (thanks to some help from this site), it gives the following as output:
11000110
1111
0
101010
Thing is, I want to find a way to pad the blanks with 0's to display a FULL eight bits....BUT, I cannot put 4 0's after say 1111 (1111 0000) because that's not the value it's representing, rather it has to be 0000 1111. I need to find a way to do that without affecting the other values?
Do I need to use masking? If so, how do I use that?
Thanks in advance!
I am using the following code to transfer bytes to binary:
char szByte[9];
int i;
BYTE bArr[400];
// Read Bytes into array here
for (i=0; i < 400; i++)
{
cout << "Byte #" << itoa(i, szByte, 10) << ": ";
cout << itoa(bArr, szByte, 2) << endl;
}
Problem with the above code, eventhough it rocks (thanks to some help from this site), it gives the following as output:
11000110
1111
0
101010
Thing is, I want to find a way to pad the blanks with 0's to display a FULL eight bits....BUT, I cannot put 4 0's after say 1111 (1111 0000) because that's not the value it's representing, rather it has to be 0000 1111. I need to find a way to do that without affecting the other values?
Do I need to use masking? If so, how do I use that?
Thanks in advance!