MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ConvertHexNibbleToByte

Function ConvertHexNibbleToByte

src/string.cpp:551–557  ·  view source on GitHub ↗

* Convert a single hex-nibble to a byte. * * @param c The hex-nibble to convert. * @return The byte the hex-nibble represents, or -1 if it is not a valid hex-nibble. */

Source from the content-addressed store, hash-verified

549 * @return The byte the hex-nibble represents, or -1 if it is not a valid hex-nibble.
550 */
551static int ConvertHexNibbleToByte(char c)
552{
553 if (c >= '0' && c <= '9') return c - '0';
554 if (c >= 'A' && c <= 'F') return c + 10 - 'A';
555 if (c >= 'a' && c <= 'f') return c + 10 - 'a';
556 return -1;
557}
558
559/**
560 * Convert a hex-string to a byte-array, while validating it was actually hex.

Callers 1

ConvertHexToBytesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected