di*********@gmail.com wrote:
trying to wrap my mind around these two exercises:
1. given an int (which is 16 bits in c),
No, in C an int has *at least* 16 bits, more are allowed (and
nowadays often the default).
if the 16 bits are:
A15A14A13A12A11A10A9A8A7A6A5A4A3A2A1A0
That's not 16 bits in any notation I have seen.
it will output
What's "it"?
an int in whose 16 bits are:
A7A6A5A4A3A2A1A0A15A14A13A12A11A10A9A8
Again, that doesn't look like bits. Does it mean bit positions
(e.g. A7 standing for the 7th bit, if we start conuting at zero)?
In that case this looks like a rotation by 8 positions.
2. given an int(which is 16bits in c) if the 16 bits are:
A15A14A13A12A11A10A9A8A7A6A5A4A3A2A1A0
it will perform a cirular right shift 5 so that the new int's 16 bits
are:
A12A11A10A9A8A7A6A5A4A3A2A1A0A15A14A13
What's your question? And how does it relate to C? Were you asked
to come up with a line of C that converts a (16-bit integer) from
the first to the second form? In that case read about the bitwise
OR operator ('|') plus the left and right shift operators, i.e.
'<<' and '>>' (but which can only be used with unsigned integers).
Here's a hint: what you need is going to look similar to
y = ( x >S ) | ( x << T );
(but there are also other ways to write the same and you may have
to logically and ('&') x with 0xFFFF before the shifts if an int
has more than 16 bits on your system) where x and y are (unsigned)
integers. All you still need to figure out are what values to use
for S and T for both the exercises. You can be pretty sure that
S + T will be 16;-)
If this is homework (and that's what it looks like) you better
post what you have tried so far and what your problem actually
is...
Regards, Jens
--
\ Jens Thoms Toerring __ _
jt@toerring.de
\__________________________
http://toerring.de