/*

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

  Copyright (C) 2015, 2016, 2017, 2018, 2020, 2021, 2022 Kai Mertens <kmx@posteo.net>
  Copyright (C) 2016  Tomás Zerolo <tomas@tuxteam.de>

  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/>.


***/


signed char hexdigit2bin (
  unsigned char hexdigit
)
{
  /*
    Convert a hexadecimal digit into a binary value.

    hexdigit – Hex value to convert.

    Returns the decimal binary value, or -1 if hexdigit was not an
    hexadecimal digit.
  */


  switch(hexdigit) {
    case '0' ... '9':
      return hexdigit - '0';

    case 'a' ... 'f':
    case 'A' ... 'F':
      return (hexdigit | 0x20) - 'a' + 10;    //convert upper to lower
  }
  return -1;
}
