convert ubyte[k..k + 1] to int

Jonathan M Davis jmdavisProg at gmx.com
Wed May 16 17:57:52 PDT 2012


On Thursday, May 17, 2012 02:32:55 Robert DaSilva wrote:
> On Wednesday, 16 May 2012 at 18:47:55 UTC, Jonathan M Davis wrote:
> > As long as you're going from big endian to little endian,
> > std.bitmanip.bigEndianToNative will do the conversion fairly
> > easily, but if
> > they're in little endian, then the nasty casting is the way to
> > go.
> > 
> > - Jonathan M Davis
> 
> Except they don't take slices. You need a helper function.
> 
> ubyte[2] _2(ubyte[] a){ubyte[2] b; assert(a.length==2); b[]=a;
> return b;}

Yeah, but it's easy enough to convert the dynamic array to a static one. It 
takes a static array, because then it's statically checked that the number of 
bytes given matches the number of bytes in the type being converted to.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list