Convert hex to binary
nrgyzer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 24 11:50:41 PDT 2015
On Friday, 24 April 2015 at 18:45:55 UTC, Jesse Phillips wrote:
> On Friday, 24 April 2015 at 18:14:07 UTC, nrgyzer wrote:
>> Hi,
>>
>> I'm looking for a function that converts my hex-string to a
>> binary representation. In Python I write the following:
>>
>> myHex = "123456789ABCDEF"
>> myBin = myHex.decode('hex')
>>
>> But how to do the same in D? Is there any function?
>>
>> Thanks for suggestions!
>
> import std.stdio;
> void main(){
> import std.conv;
> import std.format;
>
> auto i = to!ulong("123456789ABCDEF", 16);
>
> writeln(format("%b", i));
> }
Thanks to all of you for the solutions, but what if the
hex-string exceeds the limit of ulong, for instance
"123456789ABCDEF0123456789ABCDEF1234". How to convert them to a
ulong-array?
More information about the Digitalmars-d-learn
mailing list