Convert a hex string into a ubyte[] or OutBuffer

Darren via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 19 04:36:40 PDT 2014


Hi,

I'm trying to do something very basic with large numbers:

Let's say I have a hex representation of a large number:

String hexnum = "16D81B16E091F31BEF";

I'd like to convert it into a ubyte[] in order to Base64 encode 
it (or, indeed ASCII85 or Base32).

eg, [16, D8, 1B, 16, E0, 91, F3, 1B, EF]

Is there an idiomatic/simple way to do that?

For example, node's Buffer class supports the following API:

var buffer = new Buffer(hexnum, "hex");

It also supports "base64" and "utf8".

This seems like a very nice way to get string representations of 
binary data into a buffer :) Is there a D equivalent?

I was looking at how the uuid module does it, I can use that as a 
roadmap, I just wanted to check if there was a shorter way 
already present in the libs.

Many thanks,
-Darren


More information about the Digitalmars-d-learn mailing list