i had write a program, that convert a char to binary code... All were working when i had that code
int n, c, k;
n = character;
for (c = 7; c >= 0; c--)
{
k = n >> c;
if (k & 1)
printf("1");
else
printf("0");
}
But I must to write these values to an ARRAY and I edited code like u can see below and thats not worked.. Can you help me please?
void encode_char(const char character, bool bits[8]) {
int n, c, k;
n = character;
for (c = 7; c >= 0; c--)
{
k = n >> c;
if (k & 1)
bits[c] = "1";
else
bits[c] = "0";
}
printf("\n");
}
In a Arena (that controls the program) you can see error: Assertion 'encode_char('r', bits) => {0, 1, 1, 1, 0, 0, 1, 0}' failed. [got {1, 1, 1, 1, 1, 1, 1, 1}]]
'0'and'1'are bothtrue(any non-0 value istrue). Try0and1instead of the characters.bits[c] = "1";the compiler should complain because you are assigning aconst cahr *to a boolean.