Re: Byte Array Literal

2014-10-10 Thread ketmar via Digitalmars-d-learn
On Thu, 09 Oct 2014 20:08:11 + bearophile via Digitalmars-d-learn wrote: > The problem is that cast. No one wants a string, most people want > a ubyte[]. This doesn't make the cut. it's handy, people wants it, it will break almost nothing... no way. signature.asc Description: PGP signature

Re: Byte Array Literal

2014-10-09 Thread bearophile via Digitalmars-d-learn
ketmar: additionally to all bearophile said, there is another interesting thing in D: special string literals for hex data. immutable ubyte[] n = cast(typeof(n))x"deadf00d"; or even: immutable ubyte[] n = cast(typeof(n))x"de ad f 0 0 d"; spaces doesn't matter, only digits do. The prob

Re: Byte Array Literal

2014-10-09 Thread ketmar via Digitalmars-d-learn
On Thu, 09 Oct 2014 15:26:52 + Anibal via Digitalmars-d-learn wrote: additionally to all bearophile said, there is another interesting thing in D: special string literals for hex data. immutable ubyte[] n = cast(typeof(n))x"deadf00d"; or even: immutable ubyte[] n = cast(typeof(n))x"de

Re: Byte Array Literal

2014-10-09 Thread Anibal via Digitalmars-d-learn
On Thursday, 9 October 2014 at 15:41:48 UTC, bearophile wrote: You want ubytes (unsigned bytes) because 0x04 is 164 that is bigger than byte.max. I'd like bytes to be named sbyte and ubyte in D, but Walter has refused this. Bye, bearophile Got it to work, thanks a lot!

Re: Byte Array Literal

2014-10-09 Thread bearophile via Digitalmars-d-learn
You want ubytes (unsigned bytes) because 0x04 is 164 that is bigger than byte.max. I'd like bytes to be named sbyte and ubyte in D, but Walter has refused this. Bye, bearophile

Re: Byte Array Literal

2014-10-09 Thread bearophile via Digitalmars-d-learn
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];

Byte Array Literal

2014-10-09 Thread Anibal via Digitalmars-d-learn
Hi everyone, I'm just starting with D and i need a way to declare a byte array something like: byte[] arr = [ 0x00, 0xA4, 0x04]; This throws a int[] to byte[] cast error Tried also these ones byte[] arr = "\x00\xA4\x04"; byte[] arr = [ '\x00', '\xA4', '\x04']; byte[] arr = [ u'\x00', u'\xA4',