字节比特 [英] Bytes to bits

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

问题描述

我不确定这是否是组中要求的有效主题。 --Kindly

建议我使用一种技术/算法来转换

数据流(我们可以把它作为字符 - 8位数据流)

每组13位,然后进一步将这13位数据转换为

整数。当我知道

输入字符串的长度之前,我已经能够做到这一点。但是我无法概括为

数据流(或char)。

I am not sure if this a valid topic to be asked in the groups. --Kindly
suggest me a technique/algorithm by which i can convert a stream of
data (we could take it to be characters -- stream of 8 bit data) to
sets of 13 bits each and then further convert this 13 bit data to
integer. I have been able to do this when i know the length of the
input string before hand. But i am not able to generalize this for a
stream of data (or char).

推荐答案



Sync_net写道:

Sync_net wrote:
我不确定这是否是组中要求的有效主题。


不是真的,因为它不是C特定的。更好的猜测是comp.programming。

但是,在你去那里之前,我建议你更好地定义你的问题。

见下面的评论:

建议我一个技术/算法,通过它我可以转换数据流(我们可以把它作为字符 - 8位数据流)


是8比特或不是,或者你是否要求一般方法,

,无论比特数是多少?

到13比特每个


什么是设置?你在说什么这种转换如何工作?

然后进一步将这13位数据转换为整数。


什么样的整数。在C中,你有不同的风格:short,long,
signed,unsigned,char也是一个整数类型(并且还有

组合)。

当我手头知道
输入字符串的长度时,我能够做到这一点。但是我无法将这一点概括为
数据流(或char)。
I am not sure if this a valid topic to be asked in the groups.
Not really, as it''s not C specific. Better guess is comp.programming.
However, before you go there, I suggest you better define your problem.
See comments below:
suggest me a technique/algorithm by which i can convert a stream of
data (we could take it to be characters -- stream of 8 bit data)
Is it 8 bits or is it not, or are you asking for a general method,
regardless of the number of bits?
to sets of 13 bits each
What is the "set" you''re talking about. How does this conversion work?
and then further convert this 13 bit data to integer.
What sort of "integer". In C, you have different flavours: short, long,
signed, unsigned, and char is also an integer type (and there are
combinations of those as well).
I have been able to do this when i know the length of the
input string before hand. But i am not able to generalize this for a
stream of data (or char).




我不明白为什么你有这个问题。如果您要转换小于13位宽的数据,那么对于每个数据

进来,你知道你必须分配13输出位。如果你不知道怎么可能提前到来,你总是可以动态地分配

内存。你如何做到这一点取决于你选择的语言,

但你首先必须准确定义问题。



I don''t understand why you''re having problems with this. If you''re
converting data that''s less than 13 bits wide, then for every datum
coming in, you know you''ll have to allocate 13 bits for output. If you
don''t know how may are coming in advance, you can always allocate
memory dynamically. How you do that depends on your language of choice,
but you first have to define the problem precisely.


呃。 ..我的英语有点差。我很难理解你说的是什么。

可能是一个比特字段。和联盟可以帮助你。

abit field是一种空间结构结构。你可以定义

成员的多少位。

喜欢:

typedef struct {

unsigned int f1 :1;

unsigned int f2:1;

unsigned int f3:1;

unsigned int f4:1;

unsigned int类型:4;

}打包;

所以sizeof(pack)是8;

//只是google"比特字段,你会找到更有帮助的答案。


如果你定义一个如下所示的联盟:

union u_type {

pack apack;

int convert_result;

};

然后你改变apack中的每一位会得到一个新的convert_result;

eh...i am a little poor in english. and i can hardly understand what
you said.
maybe a "bit field" and a "union" can help you.
a "bit field" is a kind of spacial struct structure. you can define how
many bits a member take.
like:
typedef struct{
unsigned int f1:1;
unsigned int f2:1;
unsigned int f3:1;
unsigned int f4:1;
unsigned int type:4;
} pack;
so sizeof(pack) is 8;
//just google "bit field",you''ll find more helpful answer.

if you define a union like the following:
union u_type{
pack apack;
int convert_result;
};
then you changes every bits in "apack" will get a new "convert_result";


呃......我的英语有点差。我很难理解你说的是什么。

可能是一个比特字段。和联盟可以帮助你。

abit field是一种空间结构结构。你可以定义一个成员如何获得许多比特的


喜欢:

typedef struct {

unsigned int f1:1;

unsigned int f2:1;

unsigned int f3:1;

unsigned int f4:1;

unsigned int类型:4;


}打包;

所以sizeof(pack)是8;

//只是google" bit field",你会找到更多有用的答案。


如果你定义一个如下所示的联盟:

union u_type {

pack apack;

int convert_result;

};

然后每当你改变位数时; APACK"将获得一个新的

" convert_result";

eh...i am a little poor in english. and i can hardly understand what
you said.
maybe a "bit field" and a "union" can help you.
a "bit field" is a kind of spacial struct structure. you can define how

many bits a member take.
like:
typedef struct{
unsigned int f1:1;
unsigned int f2:1;
unsigned int f3:1;
unsigned int f4:1;
unsigned int type:4;

} pack;
so sizeof(pack) is 8;
//just google "bit field",you''ll find more helpful answer.

if you define a union like the following:
union u_type{
pack apack;
int convert_result;
};
then everytime you change bits in "apack" will get a new
"convert_result";


这篇关于字节比特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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