在Obj-C中,我曾经将无符号整数n转换为带有的十六进制字符串
NSString *st = [NSString stringWithFormat:@"%2X", n];
Run Code Online (Sandbox Code Playgroud)
我试了很长时间才把它翻译成Swift语言,但没有成功.
我仍然是编码的初学者,所以遇到了这个问题,我正在尝试将整数转换为二进制表示形式
#include <stdio.h>
int main () {
int x;
printf("input the number\n");
scanf("%d",&x);
while(x!=0) {
if (x%2)
printf("1");
else
printf("0");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以它的输出像这样12 = 0011但12 = 1100这是什么问题,我该如何解决?