Skip to content

Instantly share code, notes, and snippets.

@sleepdefic1t
Created March 8, 2020 08:15
Show Gist options
  • Save sleepdefic1t/9fc3ad22eeed623a296e5b2ff5605a6a to your computer and use it in GitHub Desktop.
Save sleepdefic1t/9fc3ad22eeed623a296e5b2ff5605a6a to your computer and use it in GitHub Desktop.
Quick Bytes To Hex, No checking
/*******************************************************************************
* This file is part of the ARK Ledger App.
*
* Copyright (c) ARK Ecosystem <[email protected]>
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#ifndef ARK_UTILS_HEX_H
#define ARK_UTILS_HEX_H
#include <stddef.h>
#include <stdint.h>
////////////////////////////////////////////////////////////////////////////////
static const uint8_t hexDigits[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
};
////////////////////////////////////////////////////////////////////////////////
// Convert Bytes to a Hex string.
// NULL terminator is added at (hexStringLen + 1)
void bytesToHex(char *dest, const uint8_t *src, size_t length) {
while (length--) {
*dest++ = hexDigits[(*src >> 4) & 0xF];
*dest++ = hexDigits[*src & 0xF];
++src;
}
*dest = '\0';
}
#endif // ARK_UTILS_HEX_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment