我不知道你是否必须处理负数,但如果你这样做,我认为该公式会导致int16的整数溢出,或者不会将预期的2的补码作为int32 .-- Bill OssmannPhilips Ultrasounde-mail:bill。
ossmann@philips.comGraeme希尔顿写于11/02/2005 10:00:12 AM:>谢谢Dave,>>我不得不捏一点让这个接受我的数据,但它仍然有效。>>但是,我坚持了下来
再看一下套接字读数,然后来了:>>来自Socket,READ BINARY x BYTE ARRAY:16001,2>然后一个公式:(x [*,1] * 256 + x [*,0])
结合两个>字节的列。>>非常快速和简单。>> - > Graeme Hilton> R& D工程师>> Schlumberger Sensa >>> David Watling在02/11/2005 14上写了以下内容:
08:>>你好Graeme,>>我写了一个byteswop公式,它可以在>>一次对数组的所有元素起作用。
将数组加载为INT16,然后运行swopper功能。
您可能>>或者也可能不想要2的cmpl函数。> >>>函数byteswop int16:>> bitOr(bitAnd(bitShift(A,-8),#H00ff),bitAnd(bitShift(A,8),
#Hff00));> >>> 2的cmpl >> asInt16(A-(A DIV 32768)* 65536);> >> >>>问候> >>> David Watling> >>> -----原始信息
----->>来自:Graeme Hilton [mailto:GHilton@slb.com]>>发送时间:2005年11月2日13:43 >> To:VRF >>主题:[vrf]字节数组转换为int16s数组
> >>>大家好,> >>>这是我最新的谜题;> >>>我正在从TCP / IP套接字读取数据。
我读取32002个字节,>>代表>> 16001 16位整数。
我不能使用READ BINARY x INT16 ARRAY1D >> 16001,因为>>数据首先显示为LSB,而To / From Socket对象通常>>它的>> MSB优先。> >>>将这些数字拼接在一起我运行
通过以下内容:>> For Each(A [2 * i] + A [(2 * i)+1] * 256)并收集结果以创建我的>> int16 >> 16001元素数组。> >>>
我的问题是这需要花费大量的时间(相比于>>其余的>程序)。
有没有人有一个非循环的方式这样做或>>另一个>节省时间的方法?> >>> --->您目前订阅vrf为:bill.ossmann@philips.com>订阅发送一个
空白电子邮件至“join-vrf@it.lists.it.agilent.com”。>要取消订阅,请发送空白电子邮件至“leave-vrf@it.lists.it.agilent.com”。>发送邮件至此邮件
列表,请发送电子邮件至“vrf@agilent.com”。>如果您需要有关邮件列表的帮助,请发送邮件至“owner-> vrf@it.lists.it.agilent.com”。>搜索“非官方vrf档案”,
“www.oswegosw.com/vrf_archive/".---您目前订阅了vrf:r***@soco.agilent.com要订阅,请发送空白电子邮件至”join-vrf@it.lists.it.agilent.com“
。要取消订阅,请发送空白电子邮件至“leave-vrf@it.lists.it.agilent.com”。要向此邮件列表发送邮件,请发送电子邮件至“vrf@agilent.com”。
如果您需要有关邮件列表的帮助,请发送邮件至“owner-vrf@it.lists.it.agilent.com”。在“www.oswegosw.com/vrf_archive/”上搜索“非官方vrf档案”。
以上来自于谷歌翻译
以下为原文
I don't know if you have to deal with negative numbers, but if you do I
think that formula will cause an integer overflow for an int16, or not give
the expected 2's complement as an int32.
--
Bill Ossmann
Philips Ultrasound
e-mail:
bill.ossmann@philips.com
Graeme Hilton wrote on 11/02/2005 10:00:12 AM:
> Thanks Dave,
>
> I had to fiddle a little to get this to accept my data, but it works
well.
>
> However, I persevered a little more with the socket reading and came
> up with this:
>
> From Socket, READ BINARY x BYTE ARRAY:16001,2
> Then a formula: (x[*,1]*256+x[*,0]) to marry the two columns of
> bytes together.
>
> Very quick and very simple.
>
> --
> Graeme Hilton
> R&D Engineer
>
> Schlumberger Sensa
>
>
> David Watling wrote the following on 02/11/2005 14:08:
> > Hi Graeme,
> > I wrote a byteswop formula which works on all elements of the array at
> > once. Load the array as INT16, then run the swopper function. You may
> > or may not want the 2's cmpl function as well.
> >
> > Function byteswop int16:
> > bitOr(bitAnd(bitShift(A,-8),#H00ff),bitAnd(bitShift(A,8),#Hff00));
> >
> > 2's cmpl
> > asInt16(A-(A DIV 32768)*65536);
> >
> >
> > Regards
> >
> > David Watling
> >
> > -----Original Message-----
> > From: Graeme Hilton [mailto:GHilton@slb.com]
> > Sent: 02 November 2005 13:43
> > To: VRF
> > Subject: [vrf] Array of bytes convert to array of int16s
> >
> > Hi All,
> >
> > Here's my latest puzzle;
> >
> > I am reading data from a TCP/IP socket. I read 32002 bytes which
> > represent
> > 16001 16-bit integers. I can't use the READ BINARY x INT16 ARRAY1D
> > 16001 as the
> > data is presented as LSB first whereas the To/From Socket object
assumes
> > it's
> > MSB first.
> >
> > To stitch these numbers together I run through the following:
> > For Each (A[2*i]+A[(2*i)+1]*256) and collect the results to create my
> > int16
> > array of 16001 elements.
> >
> > My problem is that this takes a significant amount of time (compared to
> > the rest
> > of the program). Does anyone have a non-looping way of doing this or
> > another
> > time-saving method?
> >
>
> ---
> You are currently subscribed to vrf as:
bill.ossmann@philips.com
> To subscribe send a blank email to "join-vrf@it.lists.it.agilent.com".
> To unsubscribe send a blank email to "leave-vrf@it.lists.it.agilent.com".
> To send messages to this mailing list, email "vrf@agilent.com".
> If you need help with the mailing list send a message to "owner-
>
vrf@it.lists.it.agilent.com".
> Search the "unofficial vrf archive" at "www.oswegosw.com/vrf_archive/".
---
You are currently subscribed to vrf as: [email=r***@soco.agilent.com]r***@soco.agilent.com[/email]
To subscribe send a blank email to "join-vrf@it.lists.it.agilent.com".
To unsubscribe send a blank email to "leave-vrf@it.lists.it.agilent.com".
To send messages to this mailing list, email "vrf@agilent.com".
If you need help with the mailing list send a message to "owner-vrf@it.lists.it.agilent.com".
Search the "unofficial vrf archive" at "www.oswegosw.com/vrf_archive/".