nmea是啥?
时间: 2024-02-28 10:55:34 浏览: 20
if (remainder < 10) {
push(&s, remainder); // 将当前位的值压入栈中
} else {
push(&s, remainder - 10 + 'A'); // 将当前位的值压入栈中
}
decimal /= 16;
}
char* hexadecimal = (char*)malloc(sizeof(char) * (s.top + 2)); // 分配存储空间
int i = 0;
while (!is_empty(&s)) {
char value = pop(&s); // 取出栈中元素
if (value >= 'A' && value <= 'F') {
hexadecimal[i++] = value; // 直接存储
} else {
hexadecimal[i++] = value + '0'; // 转换为字符形式
}
}
hexadecimal[i] = '\0'; // 字符串结尾
return hexadecimal;
}
int main() {
char binary[] = "101001";
char octal[] = "246";
char hexadecimal[] = "A9";
int decimal = 169;
printf("%s in binary = %d in decimal\n", binary, binary_to_decimal(binary));
printf("%s in octal = %d in decimal\n", octal, octal_to_decimal(octal));
printf("%s in hexadecimal = %d in decimal\n", hexadecimal, hex_to_decimal(hexadecimal));
printf("%d in decimal = %s in binary\n", decimal, decimal_to_binary(decimal));
printf("%d in decimal = %s in octal\n", decimal, decimal_to_octal(decimal));
printf("%d in decimal = %s in hexadecimal\n", decimal, decimal_to_hex(decimal));
return 0;
}
```
该程序定义了一个栈结构体,并实现了栈的基本操作(入栈、出栈等)。在此基础上,实现了进制转换的相关函数,包括二进制转十进制、八进制转十进制、十六进制转十进制、十进制转二进制、十进制转八进制、十进制转十六进制。在 main 函数中,演示了这些函数的使用。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)