0
|
1 |
// Copyright (c) 2006-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 the License "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 |
// f32test\plugins\hex\hex.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <f32file.h>
|
|
19 |
#include <e32test.h>
|
|
20 |
#include <e32svr.h>
|
|
21 |
#include <f32dbg.h>
|
|
22 |
|
|
23 |
inline TUint8 NibbleToHex(TUint8 aNibble)
|
|
24 |
{
|
|
25 |
return (TUint8) ((aNibble > 9) ? 'A' + aNibble - 10 : '0' + aNibble);
|
|
26 |
}
|
|
27 |
|
|
28 |
inline TUint8 HexToNibble(TUint8 aHexChar)
|
|
29 |
{
|
|
30 |
return (TUint8) ((aHexChar > '9') ? aHexChar - 'A' + 10: aHexChar - '0');
|
|
31 |
}
|
|
32 |
|
|
33 |
void Hex(TDes8& aSrcBuffer, TDes8& aDstBuffer)
|
|
34 |
{
|
|
35 |
TInt len = aSrcBuffer.Length();
|
|
36 |
aDstBuffer.SetLength(len << 1);
|
|
37 |
for (TInt n=0; n<len; n++)
|
|
38 |
{
|
|
39 |
TUint8 b = aSrcBuffer[n];
|
|
40 |
TUint8 nibble = (TUint8) ((b & 0xF0) >> 4);
|
|
41 |
aDstBuffer[n<<1] = NibbleToHex(nibble);
|
|
42 |
nibble = (TUint8) (b & 0x0F);
|
|
43 |
aDstBuffer[(n<<1)+1] = NibbleToHex(nibble);
|
|
44 |
}
|
|
45 |
}
|
|
46 |
|
|
47 |
void DeHex(TDes8& aSrcBuffer, TDes8& aDstBuffer)
|
|
48 |
{
|
|
49 |
TInt len = aSrcBuffer.Length();
|
|
50 |
aDstBuffer.SetLength(len >> 1);
|
|
51 |
for (TInt n=0; n<len; n+=2)
|
|
52 |
{
|
|
53 |
TUint8 hiNibble = HexToNibble(aSrcBuffer[n]);
|
|
54 |
TUint8 loNibble = HexToNibble(aSrcBuffer[n+1]);
|
|
55 |
|
|
56 |
aDstBuffer[n>>1] = (TUint8) ((hiNibble << 4) + loNibble);
|
|
57 |
}
|
|
58 |
}
|