|
|
|
|
Integer = 4 bytes |
sizeof(int)
will give you 1, as that device uses 64bit char (so size of char == short == int == long == long long).
Doesn't memcpy-ing from/to an array to/from an int, instead of just bitshifting and adding, introduce endianness considerations? |
|
|
sizeof
is supposed to return number of bytes an object would use in memory:Doesn't memcpy-ing from/to an array to/from an int, instead of just bitshifting and adding, introduce endianness considerations? |
first 8 bits will represent R |
return result.i
and change line 29 to tmp.i = IntegerToConvert
|
|
uint32_t header_offset; header_offset = (int) n;
gets 0 . How correctly convert it to get position in file?
How correctly convert it to get position in file? |
reading data from union member different from last written yields undefined behavior |
MiiNiPaa wrote: |
---|
I corrected myself in second post by saying that it will return size of 1 64bit byte. |
sizeof(int)
will not return 1. It has nothing to do with the size of char. 1 Byte == 8 bith4ever wrote: |
---|
Thanks this is what I wanted. And how to reverse it to join the R,G,B to integer? |
color_to_int(...)
h4ever wrote: |
---|
How correctly convert it to get position in file? |
|
|
1 Byte == 8 bit |
1.7 The C++ memory model [intro.memory] 1 The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementation defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit. The memory available to a C++ program consists of one or more sequences of contiguous bytes. Every byte has a unique address. |
Various implementations of C and C++ reserve 8, 9, 16, 32, or 36 bits for the storage of a byte.[11][12] The actual number of bits in a particular implementation is documented as CHAR_BIT as implemented in the limits.h file. |
A byte in this context is the same as an unsigned char, and may be larger than 8 bits, although that is uncommon. |
Every byte has a unique address. |
|
|
h4ever, when you say that first 8 bits will represent R do you mean the byte with the lowest address? The most significant byte in the int? Or does it not matter? |
I meant "first" as read from the left. My mistake I did not specify the direction. |
|
|