toolsandutils/e32tools/checklib/misc/endian.cpp
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Some utility functions for converting between big and little endian.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "endian.h"
       
    19 
       
    20 
       
    21 uint32_t misc::reverse_bytes(uint32_t n)
       
    22 {
       
    23     unsigned char b0 = (n >> 0*8) & 0xff;
       
    24     unsigned char b1 = (n >> 1*8) & 0xff;
       
    25     unsigned char b2 = (n >> 2*8) & 0xff;
       
    26     unsigned char b3 = (n >> 3*8) & 0xff;
       
    27 
       
    28     return (b0 << 3*8) | (b1 << 2*8) | (b2 << 1*8) | (b3 << 0*8);
       
    29 }
       
    30 
       
    31 uint16_t misc::reverse_bytes(uint16_t n)
       
    32 {
       
    33     unsigned char b0 = (n >> 0*8) & 0xff;
       
    34     unsigned char b1 = (n >> 1*8) & 0xff;
       
    35 
       
    36     return (b0 << 1*8) | (b1 << 0*8);
       
    37 }
       
    38