Concatenates int

Sean Campbell via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 10 08:14:16 PDT 2014


On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote:
> On 11/07/2014 1:18 a.m., Sean Campbell wrote:
>> perhaps I'd better state what I'm doing.
>> i have an array of 4 bytes and a want to convert them to a 32 
>> bit
>> int
>> and convert the 32 bit int back into a 4 bytes again.
>
> Small hack I use in Dakka:
>
> union RawConvTypes(T) {
> 	T value;
> 	ubyte[T.sizeof] bytes;
>
> 	ubyte[T.sizeof] opCast() {
> 		return bytes;
> 	}
> }
>
> auto iRCT = RawConvTypes!int(5);
> assert(iRCT.bytes == [5, 0, 0, 0]);
>
> Can be quite useful for evil conversions.

this may sound stupid (new to system programming) but how do you 
convert to int form ubyte[]


More information about the Digitalmars-d-learn mailing list