zoukankan
html css js c++ java
由键盘输入一个小于256的十进制正整数,然后将该数转换成八位的二进制数形式输出
#include
<
stdio.h
>
#include
<
conio.h
>
void
main()
{
int
num;
int
b0,b1,b2,b3,b4,b5,b6,b7;
printf(
"
Please input a integer number:
"
);
scanf(
"
%d
"
,
&
num);
b0
=
num
%
2
;
b1
=
num
/
2
%
2
;
b2
=
num
/
4
%
2
;
b3
=
num
/
8
%
2
;
b4
=
num
/
16
%
2
;
b5
=
num
/
32
%
2
;
b6
=
num
/
64
%
2
;
b7
=
num
/
128
%
2
;
printf(
"
%d's Binary is:%1d%1d%1d%1d%1d%1d%1d%1d\n
"
,num,b7,b6,b5,b4,b3,b2,b1,b0);
getch();
}
#include
<
stdio.h
>
#include
<
conio.h
>
#include
<
math.h
>
void
main()
{
int
num,n,i,b[
8
];
printf(
"
Please input a integer number:
"
);
scanf(
"
%d
"
,
&
num);
for
(i
=
1
;i
<
8
;i
++
)
{
n
=
pow(
2
,i);
/**/
/*
pow在BC/TC下调试通过,系统自动强制转换,但VC下会出错,形参应为double或float
*/
b[i]
=
(num
/
n)
%
2
;
}
for
(i
=
7
;i
>=
0
;i
--
)
printf(
"
%d
"
,b[i]);
getch();
}
#include
<
stdio.h
>
#include
<
conio.h
>
void
main()
{
int
m,n
=
2
,i
=
0
,j,a[
8
];
printf(
"
Please input a integer number(m>=0 and m<=255):
"
);
scanf(
"
%d
"
,
&
m);
while
(m
<
0
&&
m
>
255
)
{
printf(
"
Please input a number(m>=0 and m<=255):
"
);
scanf(
"
%d
"
,
&
m);
}
while
(m
!=
0
)
{
a[i]
=
m
%
2
;
i
++
;
m
=
m
/
2
;
}
for
(j
=
0
;j
<
8
-
i;j
++
)
printf(
"
0
"
);
for
(j
=
i
-
1
;j
>=
0
;j
--
)
printf(
"
%d
"
,a[j]);
getch();
}
查看全文
相关阅读:
Node.js理解
PayPal为什么从Java迁移到Node.js
移动开发技巧总结
Flex性能调优相关的一些总结
Flex组件的生命周期
Adobe Flash Builder 4.7 新功能详解
【Django】Cookie
【Django】路由系统
【Django】视图系统
【Django】ORM操作#2
原文地址:https://www.cnblogs.com/qixin622/p/625564.html
最新文章
.net Core——SqlSugar使用
一、SignalR使用心得
二、在 ASP.NET Core 中使用 SignalR之类库
1、类库
ids
1、Framework7
openstack swift节点安装手册2-创建rings
openstack swift节点安装手册1-节点配置
TCP/IP指纹鉴别 fingerprint
saltstack文件模块的replace操作简化
热门文章
bat判断ini文件内容
python调用win32com.client的GetObject查找进程信息及服务信息
python用win32pdh模块查看进程信息
python根据服务名获取服务启动路径
python通过操作windows系统注册表方式修改环境变量
python各种post上传文件
在Windows下开发Node.js的C/C++原生扩展
搭建Node.js开发IDE环境WebStrom5 多图
编写Node.js原生扩展
JavaScript的核心
Copyright © 2011-2022 走看看