Prakruthi said:
I have a 24 bit unsigned integer array. I would like to convert it into
a 3 byte output value.
Can someone please tell me how to go about doing this. I m a newbie to
C programming and have failed in trying to implement this conversion.
I'm not certain what you are specifying. Are you indicating that
you are working on a system on which unsigned ints happen to occupy
24 bits? And on that system, char is exactly 8 bits long?
Are you indicating that you have an array of two unsigned integers,
each of which could store 16 bits, but of which you are using 24
of the bits -- e.g., something similar to 0X YZ and you want to
extract the X Y and Z ?
Are you indicating that you have a large number of 24 bit unsigned
integers, and that there is some formulae that you have to will
operate on the list of integers and produce a 24 bit answer
that you then want to convert to bytes? Something akin to running
a CRC algorithm over the whole array and producing an output from that?
When you extract the 3 bytes from the 24 bit integer, do you want
the output bytes to be "first byte of the integer, then
second byte of the integer, then third byte of the integer" ?
Or do you want the output bytes to be "most significant 8 bits
of the integer, then next most significant 8 bits of the integer,
then least significant 8 bits of the integer" ? To clarify this,
when you have an integer as a whole, sometimes the bytes are
stored internally in an order you might not at first expect.
For example, X * 65536 + Y * 256 + Z might get stored in memory
in the byte order X then 0 then Z then Y, X0ZY so when you say you
want to extract bytes from the integer, we need to know whether
you want the order they occur in memory (e.g., X 0 Z) or if you
want the order by numeric signficance (e.g., X Y Z)