By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,435 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,435 IT Pros & Developers. It's quick & easy.

How to swap the nibbles

P: 46
Hi all,

In C, I don't know how to shift the nibble.... i.e suppose let us take 'char' data type has 1 byte(8 bits) so to shift the 4 bits to other side and vice versa...

Tell me how to do this


With Regards,
VELMURUGAN.H
Dec 22 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
Hi all,

In C, I don't know how to shift the nibble.... i.e suppose let us take 'char' data type has 1 byte(8 bits) so to shift the 4 bits to other side and vice versa...

Tell me how to do this


With Regards,
VELMURUGAN.H
you could shift the top nibble 4 bits right and the lower nibble 4 bits left then OR them together, e.g.
Expand|Select|Wrap|Line Numbers
  1.     y = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
  2.  
Dec 22 '06 #2

P: 1
you could shift the top nibble 4 bits right and the lower nibble 4 bits left then OR them together, e.g.
Expand|Select|Wrap|Line Numbers
  1.     y = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
  2.  
thats really an expert answer!! I am just a starter in C was stuck in a similar situation..and was thinking of using IF loop's..bt then,i thought of looking up on the net and this seems to be too good.and the BEST way of doing it...Thank u..
Mar 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.