• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "PublicMethods.h"
17 
Ulltoa(uintptr_t value,int8_t (& rstStr)[MAX_ITOA_BIT])18 uint32_t PublicMethods::Ulltoa(uintptr_t value, int8_t (&rstStr)[MAX_ITOA_BIT])
19 {
20     const int32_t RADIX_HEXADECIMAL = 16;
21     const int32_t dividendLength = 10;
22 
23     auto remainder = value;
24     int8_t strSpace[MAX_ITOA_BIT] = {0};
25     int8_t* curPoint = strSpace;
26     int64_t dividend = 0;
27     uint32_t rstLength = 0;
28     while (remainder || curPoint == strSpace) {
29         rstLength++;
30         dividend = remainder % RADIX_HEXADECIMAL;
31         remainder = remainder / RADIX_HEXADECIMAL;
32         if (dividend < dividendLength) { // Converted to hexadecimal
33             *curPoint++ = dividend + '0';
34         } else {
35             *curPoint++ = dividend + 'a' - dividendLength;
36         }
37     }
38     int8_t* tmpRstStr = rstStr;
39     while (curPoint > strSpace) {
40         *tmpRstStr++ = *--curPoint;
41     }
42     *tmpRstStr = 0;
43     return rstLength;
44 }
45