3 Copyright (c) 2004, Intel Corporation
4 All rights reserved. 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
;
159 if (Width
> CHARACTER_NUMBER_FOR_VALUE
- 1) {
160 Width
= CHARACTER_NUMBER_FOR_VALUE
- 1;
165 ValueIsNegative
= TRUE
;
169 Value
= (INT64
)DivU64x32 ((UINT64
)Value
, 10, &Remainder
);
170 *(TempStr
++) = (CHAR16
)(Remainder
+ '0');
173 if ((Flags
& COMMA_TYPE
) == COMMA_TYPE
) {
174 if (ValueCharNum
% 3 == 0 && Value
!= 0) {
179 } while (Value
!= 0);
181 if (ValueIsNegative
) {
186 if ((Flags
& PREFIX_ZERO
) && !ValueIsNegative
) {
193 if (!(Flags
& LEFT_JUSTIFY
)) {
194 for (; Index
< Width
; Index
++) {
195 *(TempStr
++) = Prefix
;
200 // Reverse temp string into Buffer.
202 if (Width
> 0 && (UINTN
) (TempStr
- TempBuffer
) > Width
) {
203 TempStr
= TempBuffer
+ Width
;
206 while (TempStr
!= TempBuffer
) {
207 *(BufferPtr
++) = *(--TempStr
);