Brian, you can try this sequence if you need to convert a byte in the corresponding character hexadecimal representation: swapf value, W ; Get the value nibble-swapped andlw 0x0f ; Isolate the low nibble addlw -0x0a ; Check for digit value btfsc STATUS, C ; If 0-9 skip next addlw 0x07 ; Add offset between digits and ; letters (use 0x27 for lowercase) addlw 0x3a ; Add back the value we subtracted ; for test and the offset between ; 0 and the char '0' (here W holds the high nibble char) movf value, W ; Get the value in W andlw 0x0f ; Same as high digit addlw -0x0a btfsc STATUS, C addlw 0x07 addlw 0x3a (here W holds the low nibble char) (I am sorry if the comments are unclear but I it is a little hard for me to explain better since English is not my native language.) Ciao Marco Thomas McGahee wrote: > > Brian, > IF the original nibble is <= 9 then OR it with 30H to > get ASCII "0" - "9" exactly as James Cameron showed you. > > IF the nibble has a hex value from 0AH to 0FH then > subtract 9 and OR with 40H. > > For example, if the nibble > is 0AH then subtracting 9 will give you 01H, and ORing > with 40H will give you 41H. If you desire lower case > instead of upper case, then OR with 60H instead. > > BTW, you can "subtract" 9 by adding the two's complement > of 9, which is F7H > > Hope this helps. > Fr. Tom McGahee > > ---------- > > From: Clewer,Brian > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: How to convert an 8 bit byte into two ASCII chars. > > Date: Thursday, June 11, 1998 2:50 PM > > > > James Cameron wrote: > > > > >Clewer,Brian wrote: > > >> My problem is that I have an 8 bit byte and I need to convert it > > >> into two printable chars to send to my PC. E.g.. 00111001 would be > > >> 39 (in hex). I need to send the two chars 3 and 9 to my PC. > > > > > > move the byte to W > > > swap nibbles (swapf) > > > and with 0x0f > > > or with 0x30 > > > send that byte > > > > > > move the byte to W again > > > and with 0x0f > > > or with 0x30 > > > send that byte > > > > > >Hey, I enjoyed that. Uh oh. ;-) > > > > This is ok if you use the numbers 0 to 9 but it doesn't work if you need > > HEX values from A to F. > > > > Any more ideas? > > > > Thanks, > > Brian.