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.

To swap bytes 0 and 1, and 2 and 3 of a 32-bit word, use the idiom as

Status
Not open for further replies.

sushl

Junior Member level 2
Junior Member level 2
Joined
Aug 22, 2018
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
238
Hi ,

can anyone explain me the logic of this IDIOM

(((x&0xff)<<8)¦((x&0xff00)>>8)¦((x&0xff000000)>>8)¦((x&0x00ff0000)<<8));
 

It swaps byte 0<-->1, and byte 2<-->3.

The '&0ff' is basically extracting specific sets of 8 bits at a time. Think A and 011111111

Next, the '<<' or '>>' operators then shift left or right by 8 bits.

And of course the '|' or operator combines them back again.

Quite simple really
 
  • Like
Reactions: sushl

    sushl

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top