File: porting.cxx

package info (click to toggle)
swath 0.3.0.cvs20030404
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,564 kB
  • ctags: 545
  • sloc: sh: 6,926; cpp: 3,643; makefile: 151
file content (46 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// porting.cpp - classes for code porting
// Created: 12 Jul 1996
// Author:  Theppitak Karoonboonyanan
//

#include "misc/porting.h"

bool IsHighEndianSystem()
{
    static uint16 tester = 0xff00U;
    return *(unsigned char*)&tester == 0xff;
}

uint32 ReverseBytes32(uint32 n)
{
    uint16* p = (uint16*)&n;
    *p = ReverseBytes16(*p);  p++;
    *p = ReverseBytes16(*p);
    return (n>>16) | (n<<16);
}

#ifdef PORTING_TEST

#include <iostream.h>

int main()
{
    if (IsHighEndianSystem()) {
        cout << "High-Endian!" << endl;
    } else {
        cout << "Low-Endian!" << endl;
    }

    uint16 i16 = 0xdeaf;
    cout << "ReverseBytes(" << hex << i16 << ") = ";
    cout << hex << ReverseBytes16(i16) << endl;

    uint32 i32 = 0xdeafcafe;
    cout << "ReverseBytes(" << hex << i32 << ") = ";
    cout << hex << ReverseBytes32(i32) << endl;

    return 0;
}

#endif // PORTING_TEST