Function std.digest.toHexString
Used to convert a hash value (a static or dynamic array of ubytes) to a string. Can be used with the OOP and with the template API.
char[num*2] toHexString(Order order = Order .increasing, ulong num, LetterCase letterCase = LetterCase .upper)
(
const ubyte[num] digest
);
char[num*2] toHexString(LetterCase letterCase, Order order = Order .increasing, ulong num)
(
in ubyte[num] digest
);
string toHexString(Order order = Order .increasing, LetterCase letterCase = LetterCase .upper)
(
in ubyte[] digest
);
string toHexString(LetterCase letterCase, Order order = Order .increasing)
(
in ubyte[] digest
);
The additional order parameter can be used to specify the order of the input data. By default the data is processed in increasing order, starting at index 0. To process it in the opposite order, pass Order.decreasing as a parameter.
The additional letterCase parameter can be used to specify the case of the output data. By default the output is in upper case. To change it to the lower case pass LetterCase.lower as a parameter.
Note
The function overloads returning a string allocate their return values using the GC. The versions returning static arrays use pass-by-value for the return value, effectively avoiding dynamic allocation.
Example
import std .digest .crc;
//Test with template API:
auto crc32 = digest!CRC32("The quick ", "brown ", "fox jumps over the lazy dog");
//Lower case variant:
writeln(toHexString!(LetterCase .lower)(crc32)); // "39a34f41"
//Usually CRCs are printed in this order, though:
writeln(toHexString!(Order .decreasing)(crc32)); // "414FA339"
writeln(toHexString!(LetterCase .lower, Order .decreasing)(crc32)); // "414fa339"
Example
import std .digest .crc;
// With OOP API
auto crc32 = (new CRC32Digest()) .digest("The quick ", "brown ", "fox jumps over the lazy dog");
//Usually CRCs are printed in this order, though:
writeln(toHexString!(Order .decreasing)(crc32)); // "414FA339"
Authors
Johannes Pfau