3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Routines changing value to Hex or Dec string
23 #include "EfiDriverLib.h"
25 static CHAR16 mHexStr
[] = { L
'0', L
'1', L
'2', L
'3', L
'4', L
'5', L
'6', L
'7',
26 L
'8', L
'9', L
'A', L
'B', L
'C', L
'D', L
'E', L
'F' };
30 IN OUT CHAR16
*Buffer
,
39 VSPrint worker function that prints a Value as a hex number in Buffer
43 Buffer - Location to place ascii hex string of Value.
45 Value - Hex value to convert to a string in Buffer.
47 Flags - Flags to use in printing Hex string, see file header for details.
49 Width - Width of hex value.
53 Number of characters printed.
57 CHAR16 TempBuffer
[CHARACTER_NUMBER_FOR_VALUE
];
68 // Count starts at one since we will null terminate. Each iteration of the
69 // loop picks off one nibble. Oh yea TempStr ends up backwards
73 if (Width
> CHARACTER_NUMBER_FOR_VALUE
- 1) {
74 Width
= CHARACTER_NUMBER_FOR_VALUE
- 1;
78 Index
= ((UINTN
)Value
& 0xf);
79 *(TempStr
++) = mHexStr
[Index
];
80 Value
= RShiftU64 (Value
, 4);
84 if (Flags
& PREFIX_ZERO
) {
91 if (!(Flags
& LEFT_JUSTIFY
)) {
92 for (; Index
< Width
; Index
++) {
93 *(TempStr
++) = Prefix
;
98 // Reverse temp string into Buffer.
100 if (Width
> 0 && (UINTN
) (TempStr
- TempBuffer
) > Width
) {
101 TempStr
= TempBuffer
+ Width
;
104 while (TempStr
!= TempBuffer
) {
105 *(BufferPtr
++) = *(--TempStr
);
116 IN OUT CHAR16
*Buffer
,
125 VSPrint worker function that prints a Value as a decimal number in Buffer
129 Buffer - Location to place ascii decimal number string of Value.
131 Value - Decimal value to convert to a string in Buffer.
133 Flags - Flags to use in printing decimal string, see file header for details.
135 Width - Width of hex value.
139 Number of characters printed.
143 CHAR16 TempBuffer
[CHARACTER_NUMBER_FOR_VALUE
];
151 BOOLEAN ValueIsNegative
;
153 TempStr
= TempBuffer
;
157 ValueIsNegative
= FALSE
;
160 if (Width
> CHARACTER_NUMBER_FOR_VALUE
- 1) {
161 Width
= CHARACTER_NUMBER_FOR_VALUE
- 1;
166 ValueIsNegative
= TRUE
;
170 Value
= (INT64
)DivU64x32 ((UINT64
)Value
, 10, &Remainder
);
171 *(TempStr
++) = (CHAR16
)(Remainder
+ '0');
174 if ((Flags
& COMMA_TYPE
) == COMMA_TYPE
) {
175 if (ValueCharNum
% 3 == 0 && Value
!= 0) {
180 } while (Value
!= 0);
182 if (ValueIsNegative
) {
187 if ((Flags
& PREFIX_ZERO
) && !ValueIsNegative
) {
194 if (!(Flags
& LEFT_JUSTIFY
)) {
195 for (; Index
< Width
; Index
++) {
196 *(TempStr
++) = Prefix
;
201 // Reverse temp string into Buffer.
203 if (Width
> 0 && (UINTN
) (TempStr
- TempBuffer
) > Width
) {
204 TempStr
= TempBuffer
+ Width
;
207 while (TempStr
!= TempBuffer
) {
208 *(BufferPtr
++) = *(--TempStr
);