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

Function itos

lab5/src/4/src/utils/stdlib.cpp:11–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

printfFunction · 0.50

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected