0

インクリメントしようとしている 8 バイトのカウンターがあります。後で unsigned long long 値に変換したいと思います。ただし、変換後の値はエラーになります。これはエンディアンの問題ですか、それとも間違っていますか? お知らせ下さい。

これが私のコードです:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;

#define COUNTER_LENGTH 8

typedef struct {
    uint8_t data[8];
}count_t;

static void incrementCtr(count_t* count) {
    int i;
    for (i = sizeof(count->data) - 1; i >= 0; --i) {
        if (++count->data[i] != 0) {
            break;
        }
    }
}

int main(int argc, char *argv[]){

    count_t count;
    count_t *counter;
    counter = &count;
    memset(counter ,0,sizeof(*counter));

    incrementCtr(counter);
    int i;
    for (i = 0; i < COUNTER_LENGTH; i++){
        printf("counter->data[%d] = %02X\n", i, counter->data[i]);
    }

    unsigned long long  aa = 0;
    int m;
    for(m = 0; m< COUNTER_LENGTH; m++){
        aa = aa |(counter->data[m]<< m*8);
    }
    printf("aa = %llu\n", aa);
    return 0;
}
4

1 に答える 1