469,622 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

Converting byte array to short array?

Ole
Hi,

Is there a better / faster way to convert a byte array to a short array than
to use Convert.toInt16(bytearray, i) in a loop?

Thanks
Ole
Jul 7 '06 #1
2 4313
It depends .. do you want 1 short per byte or a byte represents a high and
low of a short .. if the second then try Buffer.BlockCopy().

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Ole" <ol*@blabla.comwrote in message
news:OP**************@TK2MSFTNGP03.phx.gbl...
Hi,

Is there a better / faster way to convert a byte array to a short array
than to use Convert.toInt16(bytearray, i) in a loop?

Thanks
Ole

Jul 7 '06 #2
Yes. Don't call the Convert.ToInt16 method, it's not needed when you
convert a byte to a short. All it does is:

public static short ToInt16(byte value)
{
return value;
}

As to the loop, it can't be avoided. As a byte and short are of
different size, you can't copy the data using any block copy method.

Ole wrote:
Hi,

Is there a better / faster way to convert a byte array to a short array than
to use Convert.toInt16(bytearray, i) in a loop?

Thanks
Ole

Jul 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Bryan Parkoff | last post: by
4 posts views Thread by TRW1313 | last post: by
12 posts views Thread by AMP | last post: by
9 posts views Thread by Alberto Cardoso | last post: by
9 posts views Thread by ssubbarayan | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.