Thread overview | |||||
---|---|---|---|---|---|
|
October 17, 2012 Regarding hex strings | ||||
---|---|---|---|---|
| ||||
Maybe hex strings were invented in D1 when strings were convertible to char[]. But today strings are an array of immutable UFT-8, so I think this default type is now less useful: void main() { string data1 = x"A1 B2 C3 D4"; // OK immutable(ubyte)[] data2 = x"A1 B2 C3 D4"; // error } Gives: test.d(3): Error: cannot implicitly convert expression ("\xa1\xb2\xc3\xd4") of type string to ubyte[] Generally I'd like to use hex literals to put binary data nicely in a program, so usually I need an ubyte[] or uint[]. So I have to use something like: auto data3 = cast(ubyte[])(x"A1 B2 C3 D4".dup); So maybe the following literals are more useful in D2: ubyte[] data4a = x[A1 B2 C3 D4]; ubyte[4] data4b = x[A1 B2 C3 D4]; uint[] data5a = x[A1 B2 C3 D4]; uint[2] data5b = x[A1 B2 C3 D4]; ulong[] data6a = x[A1 B2 C3 D4 A1 B2 C3 D4]; ulong[1] data6b = x[A1 B2 C3 D4 A1 B2 C3 D4]; Bye, bearophile |
October 18, 2012 Re: Regarding hex strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Thursday, October 18, 2012 01:58:25 bearophile wrote: [snip] You posted to the wrong list. - Jonathan M Davis |
October 18, 2012 Re: Regarding hex strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Jonathan M Davis:
> You posted to the wrong list.
>
> - Jonathan M Davis
Right Jonathan, I am sorry :-) I will try again in the main D newsgroup.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation