Right Offset> = Type Width or Left Shift Number> = Type Width

I'm new to bits, I'm trying to get a 64-bit value sent using UDP.

int plugin(unsigned char *Buffer) {
     static const uint8_t max_byte = 0xFF;
     uint8_t id[8];
     id[0] = (uint8_t)((Buffer[0]) & max_byte);
     id[1] = (uint8_t)((Buffer[1] >> 8)  & max_byte);
     id[2] = (uint8_t)((Buffer[2] >> 16) & max_byte);
     id[3] = (uint8_t)((Buffer[3] >> 24) & max_byte);
     id[4] = (uint8_t)((Buffer[4] >> 32) & max_byte);
     id[5] = (uint8_t)((Buffer[5] >> 40) & max_byte);
     id[6] = (uint8_t)((Buffer[6] >> 48) & max_byte);
     id[7] = (uint8_t)((Buffer[7] >> 56) & max_byte);

}

I get a right shift error> = type width. I tried a different way as well

int plugin(unsigned char *Buffer) {
     uint64_t id = (Buffer[0] | Buffer[1] << 8 | Buffer[2] << 16 | Buffer[3] << 24 | Buffer[4] < 32 | Buffer[5] << 40 | Buffer[6] << 48 | Buffer[7] << 56);
     printf("ID %" PRIu64 "\n", id);
}

Its getting the error left shift count> = type width I checked the system on x86_64. Can someone tell me the reason why this is happening? Please suggest me a way forward.

+4
source share
1 answer

This is due to the default solid ads, mostly.

When you do this:

uint64_t id = Buffer[7] << 56;

, Buffer[7] unsigned char, int, int - 64 . "" , C.

:

const uint64_t id = ((uint64_t) Buffer[7]) << 56;

..

+5

Source: https://habr.com/ru/post/1655945/


All Articles