Posts

Showing posts with the label bit-manipulation

Interpreting bits in union fields as different datatypes in C/C++

Interpreting bits in union fields as different datatypes in C/C++ I am trying to access Union bits as different datatype for example, typedef union { uint64_t x; uint32_t y[2]; }test; test testdata; testdata.x = 0xa; printf("uint64_t: %016lxnuint32_t: %08x %08xn",testdata.x,testdata.y[0],testdata.y[1]); printf("Addresses:nuint64_t: %016lxnuint32_t: %p %pn",&testdata.x,&testdata.y[0],&testdata.y[1]); and the output is uint64_t: 000000000000000a uint32_t: 0000000a 00000000 Addresses: uint64_t: 00007ffe09d594e0 uint32_t: 0x7ffe09d594e0 0x7ffe09d594e4 The starting address pointed to by 'y' is same as starting address of 'x'; Since, both fields uses the same location shouldn't values of 'x' be 00000000 0000000a ? Why this is not happening? How the internal conversion happens in Union with different fields of different datatypes? If we want to retrieve the exact raw bits as uint32_t in the same order ...

8-bit checksum is off by one

8-bit checksum is off by one Need help figuring out an 8-bit checksum. The data is 132byte vectors. I thought I had the checksum figured out as I am able to transfer ~30kb of data before I hit the last segment of data shown blow which the checksum fails on. Its off by one. d1 = [0x00, 0x00, 0xff, 0x00, 0x00, 0x44, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xff, 0x00, 0x10, 0x11, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xff, 0x00, 0x10, 0x12, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xff, 0x00, 0x10, 0x13, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xff, 0x00, 0x10, 0x14, 0xff, 0x00, 0x10, 0x18, 0xff, 0x00, 0x10, 0x1c, 0xff, 0x00, 0x10, 0x20, 0xff, 0x00, 0x10, 0x24, 0xff, 0x00, 0x10, 0x28, 0xff, 0x00, 0x10, 0x2c, 0xff, 0x00, 0x10, 0x30, 0xff, 0x00, 0x10, 0x34, 0xff, 0x00, 0x10, 0x38, 0xff, 0x00, 0x10, 0x3c, 0xff, 0x00, 0x10, 0x40, 0xff, 0x00, 0x10, 0x44, 0xff, 0x00, ...

Use condition to check for bitwise data in dynamodb

Use condition to check for bitwise data in dynamodb I have fixed length binary range key in a DynamoDB attribute. In database with value 100110. I want to get the row which have 1 in 3/4/5 bit of attribute or any other solution to check for condition to satisfy the value exists. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.