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 18 using namespace std; 19 Ulltoa(uintptr_t value,int8_t (& rstStr)[MAX_ITOA_BIT])20uint32_t PublicMethods::Ulltoa(uintptr_t value, int8_t (&rstStr)[MAX_ITOA_BIT]) 21 { 22 const int32_t RADIX_HEXADECIMAL = 16; 23 const int32_t dividendLength = 10; 24 25 auto remainder = value; 26 int8_t strSpace[MAX_ITOA_BIT] = {0}; 27 int8_t* curPoint = strSpace; 28 int64_t dividend = 0; 29 uint32_t rstLength = 0; 30 while (remainder || curPoint == strSpace) { 31 rstLength++; 32 dividend = remainder % RADIX_HEXADECIMAL; 33 remainder = remainder / RADIX_HEXADECIMAL; 34 if (dividend < dividendLength) { // Converted to hexadecimal 35 *curPoint++ = dividend + '0'; 36 } else { 37 *curPoint++ = dividend + 'a' - dividendLength; 38 } 39 } 40 int8_t* tmpRstStr = rstStr; 41 while (curPoint > strSpace) { 42 *tmpRstStr++ = *--curPoint; 43 } 44 *tmpRstStr = 0; 45 return rstLength; 46 } 47