type conversion - Convert a slice to native (endianness) integer -


i have slice of bytes (which know integer saved little endian) , want convert them integer.

when had static-sized array no problem, have slice (ubyte[]).

is possible still convert integer, e.g. in fashion?

ubyte[] bytes = ...; uint native = littleendianslicetonative!uint(bytes); 

taking further adam has written, can write simple function like

t slicetonative(t)(ubyte[] slice) if(isnumeric!t) {     const uint s = t.sizeof,                l = min(cast(uint)s, slice.length);      ubyte[s] padded;     padded[0 .. l] = slice[0 .. l];       return littleendiantonative!t(padded); } 

you make littleendiantonative generic type mirror operations on arrays slices.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -