How to do "cast(ubyte[4])some_uint" in D1?

bearophile bearophileHUGS at lycos.com
Thu Jun 2 03:11:21 PDT 2011


Nick Sabalausky:

> In D2, I can treat a uint as an array of ubytes by doing this:
> 
> uint num = /+...whatever...+/;
> ubyte[] = cast(ubyte[4])num;
> 
> How do I do that in D1?

Using a union is probably the safest way:

union Uint2Ubyte {
    uint u;
    ubyte[4] b;
}

By the way, this of type conversions is a shady area in D.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list