/*

  Zerocat Chipflasher --- Flash free firmware, kick the Management Engine.

  Copyright (C) 2017, 2018, 2020, 2021, 2022, 2026  Kai Mertens <kmx@posteo.net>

  This file is part of Zerocat Chipflasher.

  Zerocat Chipflasher is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by the
  Free Software Foundation, either version 3 of the License, or (at your
  option) any later version.

  Zerocat Chipflasher is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License
  along with Zerocat Chipflasher.
  If not, see <http://www.gnu.org/licenses/>.


***/


# include "./bin2hexdigit.h"


signed char bin2hexdigit (
  unsigned char vbin,     // binary digit value 0..15
  unsigned char mode      // letter case mode, 0x20 (upper case) or 0x00 (lower case)
)
{
  if(vbin < 10)
    return vbin + 48;                 // '0' = 48
  if(vbin < 16)
    return (vbin + 87) & ~mode;       // 'a' - 10 = 87
  return -1;
}
