On Aug 24, 11:41 pm, Arun Vishwanathan <[email protected]> wrote:
> @don: so if a 16bit value is put into a 32 bit field and i need to read the
> value, do i need to read last 16 bits only somehow ?
>
>
>
>
>
>

As long as you are saving those 16 bits in a variable (an integer, a
bit-field or otherwise), you don't need to worry in which bytes they
are stored. In fact many machines (including Intel x86 and x86-64
architectures) use little endian format, so those 16 bits will be
stored in first 16 bits of a 32-bit integer, not last!

>
>
>
> On Wed, Aug 24, 2011 at 8:22 PM, Don <[email protected]> wrote:
> > It is most common to use 4 bytes to store an integer value, even if
> > the full range will not be used. There is no problem putting a 16-bit
> > value into a 32-bit field. The only case where this is not true is
> > when memory is extremely limited and you need to pack as much into
> > every word as possible. Do be aware that most structures are word-
> > aligned, so to actually save memory you must have several adjacent
> > elements in the structure which can be combined into one word.
> > Don
>
> > On Aug 24, 1:07 pm, Arun Vishwanathan <[email protected]> wrote:
> > > Hi all,
>
> > > I need to store a hexadecimal value in C( which would be used as a
> > request
> > > type in a  network) of around 4digits( or 16 bits-2 bytes ) in a packet
> > > structure.If my system keeps 4 bytes for an integers, is it necessary
> > that I
> > > have to declare the hex value as of type short int or so, so that it
> > takes
> > > up only 2 bytes in my packet ? What if it was required to have a hex
> > value
> > > of 3 bytes or so? How could i store it then?
> > > Also if hex value was to be of a multiple of 4 bytes would i need to use
> > > something like an integer array to store them or a float maybe?
>
> > > thanks!
>
> > > --
> > >  "People often say that motivation doesn't last. Well, neither does
> > bathing
> > > - that's why we recommend it daily."
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
>  "People often say that motivation doesn't last. Well, neither does bathing
> - that's why we recommend it daily."

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to