MCPcopy Create free account
hub / github.com/YatSenOS/YatSenOS-Tutorial-Volume-1 / itos

Function itos

lab8/src/6/src/utils/stdlib.cpp:11–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11void itos(char *numStr, uint32 num, uint32 mod)
12{
13
14 // 只能转换2~26进制的整数
15 if (mod < 2 || mod > 26 || num < 0)
16 {
17 return;
18 }
19
20 uint32 length, temp;
21
22 // 进制转换
23 length = 0;
24 while (num)
25 {
26 temp = num % mod;
27 num /= mod;
28 numStr[length] = temp > 9 ? temp - 10 + 'A' : temp + '0';
29 ++length;
30 }
31
32 // 特别处理num=0的情况
33 if (!length)
34 {
35 numStr[0] = '0';
36 ++length;
37 }
38
39 // 将字符串倒转,使得numStr[0]保存的是num的高位数字
40 for (int i = 0, j = length - 1; i < j; ++i, --j)
41 {
42 swap(numStr[i], numStr[j]);
43 }
44
45 numStr[length] = '\0';
46}
47
48void memset(void *memory, char value, int length)
49{

Callers 1

printfFunction · 0.50

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected