os/kernelhwsrv/kerneltest/f32test/plugins/version_2beta/hex/hex.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/plugins/version_2beta/hex/hex.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,58 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\plugins\hex\hex.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include <e32svr.h>
    1.24 +#include <f32dbg.h>
    1.25 +
    1.26 +inline TUint8 NibbleToHex(TUint8 aNibble)
    1.27 +	{
    1.28 +	return (TUint8) ((aNibble > 9) ? 'A' + aNibble - 10 : '0' + aNibble);
    1.29 +	}
    1.30 +
    1.31 +inline TUint8 HexToNibble(TUint8 aHexChar)
    1.32 +	{
    1.33 +	return (TUint8) ((aHexChar > '9') ? aHexChar - 'A' + 10: aHexChar - '0');
    1.34 +	}
    1.35 +
    1.36 +void Hex(TDes8& aSrcBuffer, TDes8& aDstBuffer)
    1.37 +	{
    1.38 +	TInt len = aSrcBuffer.Length();
    1.39 +	aDstBuffer.SetLength(len << 1);
    1.40 +	for (TInt n=0; n<len; n++)
    1.41 +		{
    1.42 +		TUint8 b = aSrcBuffer[n];
    1.43 +		TUint8 nibble = (TUint8) ((b & 0xF0) >> 4);
    1.44 +		aDstBuffer[n<<1] = NibbleToHex(nibble);
    1.45 +		nibble = (TUint8) (b & 0x0F);
    1.46 +		aDstBuffer[(n<<1)+1] = NibbleToHex(nibble);
    1.47 +		}
    1.48 +	}
    1.49 +
    1.50 +void DeHex(TDes8& aSrcBuffer, TDes8& aDstBuffer)
    1.51 +	{
    1.52 +	TInt len = aSrcBuffer.Length();
    1.53 +	aDstBuffer.SetLength(len >> 1);
    1.54 +	for (TInt n=0; n<len; n+=2)
    1.55 +		{
    1.56 +		TUint8 hiNibble = HexToNibble(aSrcBuffer[n]);
    1.57 +		TUint8 loNibble = HexToNibble(aSrcBuffer[n+1]);
    1.58 +
    1.59 +		aDstBuffer[n>>1] = (TUint8) ((hiNibble << 4) + loNibble);
    1.60 +		}
    1.61 +	}