如何打印出来 [英] how to print it out

查看:71
本文介绍了如何打印出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符,

我想分别打印低4位和更高4位p

单独

我该怎么做?

非常感谢!

Hi I have a char p,
I''d like to print out the lower 4 bits and higher 4 bits of p
seperately
how can i do that?
Thanks a lot!

推荐答案



< po *********** @ gmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

<po***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
我有一个字符,
我想分别打印出低4位和更高4位的页面
我该怎么做?
Hi I have a char p,
I''d like to print out the lower 4 bits and higher 4 bits of p
seperately
how can i do that?
Thanks a lot!




我更喜欢设置表格,但你不需要。如果你想要一个更简单的
方法,setup_bin_tab用来设置字符串表的逻辑可以是没有表的情况下使用的
。 nyb_l是nybble_lower等的简称(如果你理解了十六进制,你可以确定你的头部的位模式。)


Rod Pemberton

// - 工作 - 代码 -


#include< stdio.h>

#include< ; string.h>


#define nyb_l(a)((a)& 0x0F)

#define nyb_u(a)(((a) >>>>& 0x0F)


unsigned char bin_tab [16] [5];


void setup_bin_tab(void)

{

unsigned char i,j;


/ *为EOS设定nul'* /

memset(bin_tab,0,sizeof(bin_tab));


for(i = 0; i< 16; i ++)

{

for(j = 0; j <4; j ++)

{

bin_tab [i] [j] =(i&(1<< ;(3-j)))?''''':''0'';

}

}

}

int main(无效)

{

unsigned char p;


setup_bin_tab();


p = 0x82;

printf("%02x%s%s \ n&quo t;,p,bin_tab [nyb_u(p)],bin_tab [nyb_l(p)]);


p = 0x5A;

printf("% 02x%s%s \ n",p,bin_tab [nyb_u(p)],bin_tab [nyb_l(p)]);


return(0);

}



I prefer to setup tables, but you don''t need to. If you want a simpler
method, the logic that setup_bin_tab uses to setup the string table can be
used without a table. nyb_l is short for nybble_lower, etc. (If you
understand hexadecimal, you can determine the bit patterns in your head.)

Rod Pemberton

//--working--code--

#include <stdio.h>
#include <string.h>

#define nyb_l(a) ((a)&0x0F)
#define nyb_u(a) (((a)>>4)&0x0F)

unsigned char bin_tab[16][5];

void setup_bin_tab(void)
{
unsigned char i,j;

/* set nul''s for EOS */
memset(bin_tab,0,sizeof(bin_tab));

for(i=0;i<16;i++)
{
for(j=0;j<4;j++)
{
bin_tab[i][j]=(i&(1<<(3-j)))?''1'':''0'';
}
}
}
int main(void)
{
unsigned char p;

setup_bin_tab();

p=0x82;
printf("%02x %s %s\n",p,bin_tab[nyb_u(p)],bin_tab[nyb_l(p)]);

p=0x5A;
printf("%02x %s %s\n",p,bin_tab[nyb_u(p)],bin_tab[nyb_l(p)]);

return(0);
}


po **** *******@gmail.com 写道:
嗨我有一个字符,
我想打印低4位以上4分p
我怎么能这样做?
非常感谢!
Hi I have a char p,
I''d like to print out the lower 4 bits and higher 4 bits of p
seperately
how can i do that?
Thanks a lot!




#include< stdio.h> ;


int main(无效){

unsigned char p = 42; / *或其他* /

char hibits [5] = {''0'','0'','0'','0'',0};

char lobits [5] = {''0'','0'','0'','0'',0};


if(p> 127){

hibits [0] =''1';

p - = 128;

}

if(p> 63){

hibits [1] =''1';

p - = 64;

}

if(p> 31){

hibits [2] =''1';

p - = 32;

}

if(p> 15){

hibits [3] =''1';

p - = 16;

}

if(p> 7){

lobits [0] =''1 '';

p - = 8;

}

if(p> 3){

lobits [ 1] =''1'';

p - = 4;

}

if(p> 1){

lobits [2] =''1'';

p - = 2;

}

if(p == 1 ){

lobits [3] =''1'';

}

printf(" Hibits:%s \ n",hibits);

printf(" Lobits:%s \ n",lobits);

返回0;

}


-

如果您通过Google发布,请阅读< http://cfaj.freeshell.org/google> ;



#include <stdio.h>

int main(void) {
unsigned char p = 42; /* or whatever */
char hibits[5] = {''0'', ''0'', ''0'', ''0'', 0};
char lobits[5] = {''0'', ''0'', ''0'', ''0'', 0};

if (p > 127) {
hibits[0] = ''1'';
p -= 128;
}
if (p > 63) {
hibits[1] = ''1'';
p -= 64;
}
if (p > 31) {
hibits[2] = ''1'';
p -= 32;
}
if (p > 15) {
hibits[3] = ''1'';
p -= 16;
}
if (p > 7) {
lobits[0] = ''1'';
p -= 8;
}
if (p > 3) {
lobits[1] = ''1'';
p -= 4;
}
if (p > 1) {
lobits[2] = ''1'';
p -= 2;
}
if (p == 1) {
lobits[3] = ''1'';
}
printf("Hibits: %s\n", hibits);
printf("Lobits: %s\n", lobits);
return 0;
}

--
If you''re posting through Google read <http://cfaj.freeshell.org/google>


po ******** ***@gmail.com 写道:
嗨我有一个字符,
我想打印出p的低4位和高4位
单独
我该怎么做?
非常感谢!
Hi I have a char p,
I''d like to print out the lower 4 bits and higher 4 bits of p
seperately
how can i do that?
Thanks a lot!



我放弃了,你怎么样?你想怎么打印这些位?什么问题

你有尝试吗?跟我说话。给我看一些C代码。


-

Joe Wright

所有东西都应尽可能简单,但是并不简单。

---阿尔伯特爱因斯坦---


I give up, how can you? How do you want to print the bits? What problems
do you have when you try it? Talk to me. Show me some C code.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


这篇关于如何打印出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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