In essence, the older character mapping software did this. Nominally, all keys are ASCII on a normal keyboard if you factor in the ALT and CTRL and SHIFT offsets.
Take ASCII value, convert to hex, you have the keycode. A programmers multibase translating calculator will convert for you. Try Programmer's Heaven for one, they are out there inexpensively, and the better Ti's can also do this in a not-so-direct manner.
If you want to do this manually, you work right to left, and remember four binary bits per hex digit and that it is easiest that when doing by hand that you first take decimal to binary and then rebuild hex digits from that if you want hyper-simple calc path.
Lets take ASCII 127 (yes I am cheating). 127 is binary 11111111 so that calcs to hex FF (highest decimal value that hex 0F (or just F for hex digit discussion's sake) is, is 15 (16 possibles including 0 decimal) and that is four bits (8+4+2+1 in decimal by place of bit position which progresses bigger to left from right). Lets now take 63 decimal-- that is more than one hex digit, it is over 16-- so lets take this to binary.
Conversion from decimal to binary is an iterative calc, goes like this:
we are working right to left, so I will invert the process for you:
64-1 is 63 with a 1 remainder
63-2 is 61 with a 10 "
61-4 is 57 with a 100
57-8 is 49 with a 1000
49-16 is 36 with a 00000 Result is even, no remainder, but need 0 as place holder.
63-32 is 31 with a 100000
31-64 does not compute to a positive, but is 16 +15.
So, now we have an addition problem.
_00101111
+00010000
+00001111
yeilds
01000000 binary and that is right as 64-1 (to allow for 0 being valid) is 63.
that help some??? Take extended ASCIIvalue , convert to binary. Now for hex conversion.
Left digit is binary 0100 and that is hex 4. Right digit is binary 0000, hex 0. Conversion complete when we marry hex digit results to 40.
Welcome to PART of what you will be doing with IPV6 addressing, which takes binary IP octets and uses HEX instead as well as allowing different number of Hex digits per hextet structure of IP definition, but that is a different starting point.
If you are familair with boolean ANDing logic, will show you the left to right method if you want, which is what I use internally, but this is above method is easier to program into a HUMAN brain,IMHO.
Rule set, boolean, for left to right is:
If negative, lead 0.
If positive AND even, lead 0.
If positive AND odd, lead 1.
AND, subtract left to right bitwise using byte size leftward progressive padding chunk steppingss to get correct hex result for a Modulo 8 machine if converting to hex. Modulo 16 machines get 2 byte chunking\padding, modulo 32 bit machines are far in the future in pure sense but take a 4 byte chunking. Right now most hardware is building larger words from Modulo 8 or Modulo 16 RAM storage,and RAM is not truely Modulo 32 yet.
HTH. John.