Write in C. ;)
Has already been done, ages before this question was posted, because this problem is ages old. And dd is significantly faster (97 msec) even on my old server:
$ time dd if=tmp/TestFile.bin conv=swab of=tmp/TestFile.out
32768+0 records in
32768+0 records out
16777216 bytes (17 MB) copied, 0.0970995 s, 173 MB/s
real 0m0.130s
user 0m0.020s
sys 0m0.080s
$ od -h tmp/TestFile.bin | head
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0fac e0ff 0000 0000 dead beef
0000040 0000 0000 0000 0000 0000 0000 0000 7800
0000060 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000 4946 4900 0000 0001 0000 0002 0000 0000
0001020 ffff ffff ffff ffff ffff ffff ffff ffff
*
0002000 0000 0001 0000 000b 0000 0000 00ef fc00
0002020 0000 0000 0000 0400 0000 0000 0002 e800
$ od -h tmp/TestFile.out | head
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 ac0f ffe0 0000 0000 adde efbe
0000040 0000 0000 0000 0000 0000 0000 0000 0078
0000060 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000 4649 0049 0000 0100 0000 0200 0000 0000
0001020 ffff ffff ffff ffff ffff ffff ffff ffff
*
0002000 0000 0100 0000 0b00 0000 0000 ef00 00fc
0002020 0000 0000 0000 0004 0000 0000 0200 00e8
$
Just for fun, doing the same thing on a cdrom image file:
$ time dd slackware-13.0-install-d2.iso conv=swab of=tmp/delete.me
1315400+0 records in
1315400+0 records out
673484800 bytes (673 MB) copied, 4.05028 s, 166 MB/s
real 0m4.173s
user 0m0.640s
sys 0m3.370s
$
The speed of dd on my server is clearly limited by the disks, as working on a tmpfs in RAM runs at about double speed compared to running with files on disk:
$ time dd if=/tmp/TestFile.bin conv=swab of=/tmp/TestFile.out
32768+0 records in
32768+0 records out
16777216 bytes (17 MB) copied, 0.0506392 s, 331 MB/s
real 0m0.056s
user 0m0.020s
sys 0m0.030s
$
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)