getting the bytes of a long
Bill Baxter
dnewsgroup at billbaxter.com
Fri Nov 30 09:25:42 PST 2007
Jason House wrote:
> Bill Baxter wrote:
>
>> jc wrote:
>>> hi,
>>>
>>> is there a way to stuff the 8 bytes of a long into a byte array other
>>> than to use a union to achive that?
>>>
>>> cheers
>>> jc
>> Take the address, cast to byte, deref byte by byte:
>>
>> (cast(ubyte*)&the_long)[0];
>> (cast(ubyte*)&the_long)[1];
>> (cast(ubyte*)&the_long)[2];
>> ...
>>
>> --bb
>
> Does gdc run on any little endian machines? I'm not sure which way arrays
> grow on such machines, but I think this could would give the reverse byte
> order of a big endian machine.
Yep. Order most definitely depends on endianness. Intel is little
endian. If you're planning on sending those bytes over a network you'd
better swap em if you've got version(LittleEndian).
--bb
More information about the Digitalmars-d-learn
mailing list