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

Function itos

lab6/src/1/src/utils/stdlib.cpp:11–42  ·  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 return;
17 }
18
19 uint32 length, temp;
20
21 // 进制转换
22 length = 0;
23 while(num) {
24 temp = num % mod;
25 num /= mod;
26 numStr[length] = temp > 9 ? temp - 10 + 'A' : temp + '0';
27 ++length;
28 }
29
30 // 特别处理num=0的情况
31 if(!length) {
32 numStr[0] = '0';
33 ++length;
34 }
35
36 // 将字符串倒转,使得numStr[0]保存的是num的高位数字
37 for(int i = 0, j = length - 1; i < j; ++i, --j) {
38 swap(numStr[i], numStr[j]);
39 }
40
41 numStr[length] = '\0';
42}
43
44void memset(void *memory, char value, int length)
45{

Callers 1

printfFunction · 0.50

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected