471,872 Members | 1,046 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,872 software developers and data experts.

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 4448
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.