Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Swapping a byte's nibbles

For those compilers that do not have a built-in function for swapping a byte's nibbles, a simple user function can be created:


Code C - [expand]
1
2
3
4
unsigned char SwapNibbles (unsigned char x)
{
  return ((x >> 4) & 0x0F) | ((x << 4) & 0xF0);
}



And a couple of function call examples:


Code C - [expand]
1
2
3
unsigned char ch1, ch2;
ch1 = SwapNibbles(0xA3);  //ch1=0x3A
ch2 = SwapNibbles(ch1);   //ch2=0xA3



Happy coding!
Alexandros

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
alexxx
Read time
1 min read
Views
567
Last update

More entries in Uncategorized

More entries from alexxx

Share this entry

Back
Top