Convert Little Endian to Big Endian

前端 未结 13 1826
慢半拍i
慢半拍i 2020-11-27 16:34

I just want to ask if my method is correct to convert from little endian to big endian, just to make sure if I understand the difference.

I have a number which is st

相关标签:
13条回答
  • 2020-11-27 16:55

    You could do this:

    int x = 0x12345678;
    
    x = ( x >> 24 ) | (( x << 8) & 0x00ff0000 )| ((x >> 8) & 0x0000ff00) | ( x << 24)  ; 
    
    printf("value = %x", x);  // x will be printed as 0x78563412
    
    0 讨论(0)
提交回复
热议问题