Byte Array Literal
    bearophile via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Oct  9 08:36:10 PDT 2014
    
    
  
Anibal:
> byte[] arr = [ 0x00, 0xA4, 0x04];
>
> This throws a int[] to byte[] cast error
You want ubytes (unsigned bytes) because 0x04 is 164 that is 
bigger than byte.max.
So use:
ubyte[] arr = [ 0x00, 0xA4, 0x04];
> I also tried
> byte[] arr = [cast(byte) 0x00, cast(byte)0xA4, cast(byte) 0x04];
> and this at least compiles
Generally in D try to mimize as much as possible the usage of 
cast().
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list