Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fastest way to single hex digit => decimal

Name: Anonymous 2012-01-06 8:46

char hexchartodec_map[256] = {
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
};

char hexchartodec(char i) {
        return hexchartodec_map[i];
}

Name: Anonymous 2012-01-06 22:10

python version:

# This program 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.

# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>;.

def hex_char_to_decimal_value(h):
   if h == "0":
      return 0
   elif h == "1":
      return 1
   elif h == "2":
      return 2
   elif h == "3":
      return 3
   elif h == "4":
      return 4
   elif h == "5":
      return 5
   elif h == "6":
      return 6
   elif h == "7":
      return 7
   elif h == "8":
      return 8
   elif h == "9":
      return 9
   elif h == "A" or h == "a":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("0")))
   elif h == "B" or h == "b":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("1")))
   elif h == "C" or h == "c":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("2")))
   elif h == "D" or h == "d":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("3")))
   elif h == "E" or h == "e":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("4")))
   elif h == "F" or h == "f":
      return int(str(hex_char_to_decimal_value("1")) + str(hex_char_to_decimal_value("5")))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List