When you have an array of chars/bytes whatever, and you want to put them all into ints you do...
Code: Select all
int x = buf[10] | buf[11] | buf[12] <and so on...>
-JL
Code: Select all
int x = buf[10] | buf[11] | buf[12] <and so on...>
Reorganize your data area so that the offset is a multiple of 8, and do:piranha wrote:This would be in my OS, so no standard functions...
This is specificaly for FS reading, in which the super-block's info for the number of blocks in the data area at offset 0x019C, length is 8 bytes....how to convert that into a long int...?
-JL
Code: Select all
struct superblock {
uint64_t length;
};
uint64_t sb_length_member;
struct superblock *sb = NULL;
sb = (struct superblock *)malloc(sizeof(struct superblock));
..int fd = open("/dev/something", O_RDONLY);
..lseek(fd, offset, ...);
..read(fd, sb, 8);
sb_length_member = sb->length;
Code: Select all
uint32_t val = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
Code: Select all
uint32_t val = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
(I hope the compiler is smart enough to reoptimize the 16 opcodes necessary for that. )Code: Select all
uint32_t val = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];