有一个短,需要提取8位所以我可以有一个字符 [英] have a short, need to extract 8 bits so I can have a char

查看:65
本文介绍了有一个短,需要提取8位所以我可以有一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hola!


我有一组代表数据流的短裤。这个数据是紧密打包的,所以某些元素实际上可能包含比一个变量更多的数据。


我是解密这个流。打包到这个数组中的第一个变量

恰好是一个简短的,这意味着我通过一个简单的任务逃脱:

myFirstVariable = myArray [0];


我的问题是mySecondVariable是一个char。这意味着

我需要的char占myArray的50%[1]。


我怎样才能得到那8位,只有那8位?这是一个相当大的

粘贴点,因为它自然地跟随myThirdVariable在myArray [1]的后半部分开始

。在试图从这个数据流中找到正确的答案时,我已经尝试了各种疯狂的,b / b
在黑暗中进行的演员阵容等等。 ,显然没有任何运气。


我的新机智将是尝试分裂,或者,同样的道理,

myArray上的按位操作[1]试图得到我的8位。我是朝着正确的道路前进的吗?如果没有,是否有某种灵魂引导我

朝向光明?

任何帮助或建议非常感谢!


Danny

解决方案

>我有一组表示数据流的短路。这个数据

紧密包装,所以某些元素实际上可能包含
多个变量的数据。

我是解密这个流。打包到这个
数组中的第一个变量碰巧是一个简短的,这意味着我得到了一个简单的赋值:
myFirstVariable = myArray [0];

我的问题是mySecondVariable是一个炭。这意味着
我需要的char占myArray [1]的50%。

如何获得这8位,只有8位?这是一个非常好的
大点,因为它自然地跟随myThirdVariable
在myArray [1]的后半部分开始。在尝试从这个数据流中得到
正确的答案时,我尝试了各种疯狂的,在黑暗中摸索的演员等等,显然没有任何运气。 />
我的新机智将尝试分裂,或者,同样的方式,在myArray [1]上逐位操作以试图获得我的8位。我是朝着正确的道路前进吗?如果没有,某种灵魂会引导我走向光明吗?




这个问题可以解决,但要解决一些额外的信息
需要
。如果流中的数据很短(我假设你的平台上是一个16位整数),那么最重要的字节是第一个还是最后一个?



-

Peter van Merkerk

peter.van.merkerk(at)dse.nl


这个问题可以解决,但要解决这个问题需要一些额外的信息。如果流中的数据很短(我假设你的平台上是16位整数),那么最重要的字节是第一个还是最后一个?

-
Peter van Merkerk
peter.van.merkerk(at)dse.nl



first


< blockquote>

" Danny Anderson" < BT ***** @ i.hate.spam>在留言中写道

news:pa **************************** @ i.hate.spam .. 。

Hola!

我有一组表示数据流的短路。这些数据紧凑,因此某些元素实际上可能包含的数据比一个变量更多。


听起来你宁愿拥有一个char数组,那么,并不是一个简短的
数组。你应该将数组转换为chars,它们会更容易混乱

with。

我的问题是mySecondVariable是一个char。这意味着我需要的char占myArray的50%[1]。


使用char数组,你可以通过将myArray [0]转换为

短来获得最初的短片,然后你就得到了char想要在myArray [2]。这可能是一个问题,如果你的字边界很短,但我认为

字符串流可以满足你的需求,而不需要太多的工作。

我的新机智将尝试分裂,或者,同样的方式,对myArray [1]进行按位操作,试图得到我的8位。我是朝着正确的道路前进吗?如果没有,某种灵魂会引导我走向光明吗?


我想我会为此尝试一个字符串流,只需:


任何帮助或建议非常感谢!
<丹尼



Hola!

I have an array of shorts that represents a stream of data. This data is
packed in tight, so certain elements may actually contain data for more
than one variable.

I am to decipher this stream. The first variable packed into this array
happens to be a short, meaning I get away with a simple assignment:
myFirstVariable=myArray[0];

My problem is that mySecondVariable is a char. What that means is that
the char I need is making up 50% of myArray[1].

How can I get those 8 bits, and only those 8 bits? This is a pretty big
sticking point, because it follows naturally that myThirdVariable starts
in the second half of myArray[1]. In attempting to come up with the right
answer from this datastream, I have tried all kinds of crazy,
groping-in-the-dark kinds of casts, etc., obviously without any luck.

My new tact is going to be trying division, or, along the same vein,
bitwise operations on myArray[1] in an attempt to get my 8 bits. Am I
heading down the right path? If not, would some kind soul steer me
towards the light?
Any help or suggestions much appreciated!

Danny

解决方案

> I have an array of shorts that represents a stream of data. This data
is

packed in tight, so certain elements may actually contain data for more than one variable.

I am to decipher this stream. The first variable packed into this array happens to be a short, meaning I get away with a simple assignment:
myFirstVariable=myArray[0];

My problem is that mySecondVariable is a char. What that means is that the char I need is making up 50% of myArray[1].

How can I get those 8 bits, and only those 8 bits? This is a pretty big sticking point, because it follows naturally that myThirdVariable starts in the second half of myArray[1]. In attempting to come up with the right answer from this datastream, I have tried all kinds of crazy,
groping-in-the-dark kinds of casts, etc., obviously without any luck.

My new tact is going to be trying division, or, along the same vein,
bitwise operations on myArray[1] in an attempt to get my 8 bits. Am I
heading down the right path? If not, would some kind soul steer me
towards the light?



That problem can be solved, but to solve it some additional information
is needed. If the data in the stream is a short (I assume that is a
16-bit integer on your platform), does the most significant byte come
first or last?

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


That problem can be solved, but to solve it some additional information
is needed. If the data in the stream is a short (I assume that is a
16-bit integer on your platform), does the most significant byte come
first or last?

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


first



"Danny Anderson" <bt*****@i.hate.spam> wrote in message
news:pa****************************@i.hate.spam...

Hola!

I have an array of shorts that represents a stream of data. This data is
packed in tight, so certain elements may actually contain data for more
than one variable.
It sounds like you''d rather have a char array, then, not really a short
array. You should cast the array to chars where they''ll be easier to mess
with.
My problem is that mySecondVariable is a char. What that means is that
the char I need is making up 50% of myArray[1].
With a char array, you can get the initial short by casting myArray[0] to a
short, then you''ve got the char you want at myArray[2]. This might be a
problem if you have a short off of word boundaries, but then I think a
stringstream may satisfy your needs, without too much work.
My new tact is going to be trying division, or, along the same vein,
bitwise operations on myArray[1] in an attempt to get my 8 bits. Am I
heading down the right path? If not, would some kind soul steer me
towards the light?
I think I''d try a stringstream for this, just:


Any help or suggestions much appreciated!

Danny



这篇关于有一个短,需要提取8位所以我可以有一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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