编写程序以打印出16位数的二进制值 [英] Writing a program to print out the binary value of a 16 bit number

查看:85
本文介绍了编写程序以打印出16位数的二进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好;


我是新手。


分配了家庭作业,我无法入门。


作业如下:


编写程序打印出16位数字的二进制值。


创建整数i,count和mask。

设置''我将十六进制值设为0x1b53。

将掩码设置为值0x8000。为什么?


打印一行显示i的十六进制值,然后是二进制值的前导,如下所示:

十六进制值= 1b53二进制=


使用for循环循环16次并打印16位数,使用count作为循环计数器


测试每个数字值,按位并且''我'用''掩码''

当结果为按位且为真时,打印数字''1'

当结果为按位且为假,打印数字''0'


然后将面具移到右边一个地方


打印一个新行然后退出


使用prtscrn并使用控制台输出制作代码的硬拷贝。

额外:使用计数模数并打印后的空格每4位数字使二进制文件更容易阅读


输出应如下所示:

十六进制值= 1b53,二进制= 0001 1011 0101 0011


有什么建议吗?

Hello;

I am a newbie.

A homework assignment was assigned and I am having trouble getting started.

The assignment reads:

Write a program to print out the binary value of a 16 bit number.

Create integers i, count, and mask.
Set ''i'' to a hex value of 0x1b53.
Set mask to a value of 0x8000. Why?

print a line to show the hex value of i and then the leader for the binary value like this:
Hex value = 1b53 Binary=

Use a for loop to loop 16 times and print 16 digits, using count as the loop counter

To test for each digit value, bitwise and ''i'' with ''mask''
when the result for the bitwise and is true, print the number ''1''
when the result for the bitwise and is false, print the number ''0''

then shift mask one place to the right

print a new line and then quit

Use prtscrn and make a hard copy of the code with the console output.
Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read

The output should look like this:
Hex value = 1b53, Binary= 0001 1011 0101 0011

Any suggestions?

推荐答案


十六进制值= 1b53,二进制= 0001 1011 0101 0011
Hex value = 1b53, Binary= 0001 1011 0101 0011



要查看设置此位:

To see of this bit is set:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号



看到这一位设置:
To see of this bit is set:
展开 | 选择 | Wrap | 行号



好​​吧,对于熟悉编程的人来说,提示可能就足够了......


我从未参加任何编程课程。我们在C的第4周。


嗯,谢谢快速回复。
Well, maybe the hint is enough for a person familiar with programing...

I have never taken any programming classes. We are in our 4th week of C.

Well, thanks for the quick reply.



好​​吧,这就是我到目前为止......我迷失了。


#include< stdio .h>


int main()

{

int i,count,mask;

mask = 0x8000;

i = 0x1b53;

printf(" Hex value =%d,Binary =%d \ n",i,mask);

for(i = 0; i< = 15; i = i + 1)

printf(" 1");

printf( 0);

返回0;

}

OK, this is what I have so far.... I am lost.

#include <stdio.h>

int main ()
{
int i, count, mask;
mask=0x8000;
i=0x1b53;
printf("Hex value = %d, Binary = %d\n", i, mask);
for (i = 0; i <= 15; i = i + 1)
printf("1");
printf("0");
return 0;
}


这篇关于编写程序以打印出16位数的二进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆