9 years, 5 months ago.  This question has been closed. Reason: Unclear question

Why is my variable never populated?

Hi All,

Im having a bit of trouble storing a bit setting.

My (sample) code:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx

int main() {
    pc.baud(19200);

    uint64_t i,x = 0;
    uint64_t hex1 = 255721421627155024;

    uint8_t bits[64];

    // delete this line when you try to reproduce, its only here for reference what I was doing.
    pc.printf("hex1 = %s\n\n", i642b(buffer, hex1));

    for (i = ((uint64_t)1 << 63); i > 0; i >>= 1)
    {
        bits[x] = (((uint64_t)(hex1 & i) == i) ? 0x01:0x00);
        pc.printf("bits[%d] = %d == %d\n", x, bits[x], (((uint64_t)(hex1 & i) == i) ? 0x01:0x00));
        x++;
    }
}

I would have expected this output:

hex1 = 00 00 00 11 10 00 11 00 10 00 00 01 01 00 01 11 00 11 00 01 10 00 10 11 01 10 00 10 01 01 00 00

bits[0] = 0 == 0
bits[1] = 0 == 0
bits[2] = 0 == 0
bits[3] = 0 == 0
bits[4] = 0 == 0
bits[5] = 0 == 0
bits[6] = 1 == 1
bits[7] = 1 == 1
bits[8] = 1 == 1
bits[9] = 0 == 0
..........

But instead I get this:

hex1 = 00 00 00 11 10 00 11 00 10 00 00 01 01 00 01 11 00 11 00 01 10 00 10 11 01 10 00 10 01 01 00 00

bits[0] = 0 == 0
bits[1] = 0 == 0
bits[2] = 0 == 0
bits[3] = 0 == 0
bits[4] = 0 == 0
bits[5] = 0 == 0
bits[6] = 0 == 1
bits[7] = 0 == 1
bits[8] = 0 == 1
bits[9] = 0 == 0
..........

So it looks like bits[] is never being populated. Does somebody knows why this is? I'm not seeing it....

Thanks in advance,

Found the problem...

Apparently it didn't like the: uint64_t x = 0;

and next use that uint64_t as key inside a array.

posted by Henry Pauli 29 Nov 2014