bswap
ã¢ã»ã³ãã©å½ä»¤(bswap)ã使ãããã®Cè¨èªç¨ãã¯ã*1ã
Windows7(x64)ãVisualStudio2010ã32ããããã·ã³ã¢ã¼ããã¯ãã£åããã«ãã§ç¢ºèª...ãWin32ã³ã³ã½ã¼ã«ã¢ããªãã¨ãããã¨ã§ãã
#include <iostream> #include <iomanip> using namespace std; #define bswap64(mq) \ __asm lea edx, [mq]\ __asm mov eax, [edx]\ __asm bswap eax\ __asm xchg eax, [edx+4]\ __asm bswap eax\ __asm mov [edx], eax #define bswap32(md) \ __asm lea edx, [md]\ __asm mov eax, [edx]\ __asm bswap eax\ __asm mov [edx], eax #define bswap16(mw) \ __asm lea edx, [mw]\ __asm mov ax, [edx]\ __asm xchg ah, al\ __asm mov [edx], ax int main() { unsigned long long q =0x0102030405060708; bswap64(q); cout <<"0x" <<setfill('0') <<setw(16) <<hex <<q <<endl; unsigned int d =0x01020304; bswap32(d); cout <<"0x" <<setfill('0') <<setw(8) <<hex <<d <<endl; unsigned short w =0x0102; bswap16(w); cout <<"0x" <<setfill('0') <<setw(4) <<hex <<w <<endl; }
0x0807060504030201 0x04030201 0x0201
*1:bswapã¯ã¨ã³ãã£ã¢ã³ãã¹ãå¤æ´ããããã«ãããããã