cast
    Stewart Gordon 
    smjg_1998 at yahoo.com
       
    Fri Nov 17 05:32:32 PST 2006
    
    
  
Boris Shomodjvarac wrote:
> Hi,
> 
> I have a array of ubyte-s and need to cast for example from 4-th element
> to 8-th element into int, anyone knows how to do that? 
> 
> example:
> 
> ubyte buffer[1024];
> 
> listener.receiveFrom(buffer, address);
> 
> writefln("Transaction ID: %s", cast(int)buffer[4 .. 8]);
> 
> Thanks.
An array cannot be converted to an int.  An array of bytes can, however, 
be converted to an array of ints.
     (cast(int[]) cast(void[]) buffer[4..8]) [0]
If your data needs to be portable between big-endian and little-endian 
platforms, you'll need to be a bit more careful.
Stewart.
-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------
My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
    
    
More information about the Digitalmars-d-learn
mailing list