文章
10
粉丝
36
获赞
0
访问
4.4k
#include <bits/stdc++.h>
using namespace std;
// 将十进制字符串转换为二进制字符串
void decimalToBinary(char a[], char binary[]) {
int len = strlen(a);
int k = 0;
while (len > 0) {
binary[k++] = ((a[len - 1] - '0') % 2) + '0';
int carry = 0;
for (int i = 0; i < len; i++) {
int cur = (a[i] - '0') + carry * 10;
a[i] = (cur / 2) + '0';
carry = cur % 2;
}
// 去除前导零
while (len > 0 && a[0] == '0') {
for (int i = 0; i < len - 1; i++) {
a[i] = a[i + 1];
}...
登录后发布评论
暂无评论,来抢沙发