Now why didn't I see that! It makes setting the radix as simple as Radix ds 1 ;radix to change data from RadixBin = Radix.1 ;B 01000011 RadixOct = Radix.4 ;O 01010000 RadixDec = Radix.2 ;D 01000101 RadixHex = Radix.3 ;H 01001001 Radix :Set ;enter with "B", "O", "D" or "H" in W mov radix, w inc radix retp :Change jnb RadixHex, @:HexOut :Hex ;convert from Hex by Andrew Warren from ;http://www.sxlist.com/ubicom/lib/math/radix mov W, #'0' snb CHAR1.6 mov W, #'A'-10 sub CHAR1, W mov W, #'0' snb CHAR2.6 mov W, #'A'-10 sub CHAR2, W mov W, <>CHAR1 add W, CHAR2 retp :HexOut jnb RadixOct, @:OctOut ; etc... ; etc... ; etc... ;by James Newton and Nikolai Golovchenko ;Enter with an ASCII character representing the desired base for a radix conversion. ;B=Binary ;D=Decimal ;H=Hex ;O=Octal ; ;Challenge 1: exit with a different bit set for each base. ;Challenge 2: exit with the radix (2 for binary, 10 for decimal, 16 for hex, 8 for octal) ;Challenge 3: exit with a jump table index ; ;My best: Radix ds 1 ;radix to change data from RadixBin = Radix.1 ;B 01000011 RadixOct = Radix.4 ;O 01010000 RadixDec = Radix.2 ;D 01000101 RadixHex = Radix.3 ;H 01001001 Answer1 inc radix ;B=3,D=5,H=9,N=15,O=16 ;done jb radixBin, binary jb radixDec, decimal jb radixHex, hex jb radixOct, octal Answer2 inc radix clrb radix.6 ;B=3,D=5,H=9,O=16 sb radix.2 ;if not D (5) dec radix ;B=2,D=5,H=8,O=15 snb radix.1 ;if D or H rl radix ;B=2,D=11,H=17,O=15 clrb radix.0 ;B=2,D=10,H=16,O=14 snb radix.2 ;if O clrb radix.1 ;B=2,D=10,H=16,O=12 clrb radix.2 ;B=2,D=10,H=16,O=8 ;or... inc radix mov w, #2 snb RadixOct mov w, #8 snb radixDec mov w, #10 snb radixHex mov w, #16 ;and if you want to handle N = nibble inc radix mov w, #8 snb radixDec mov w, #5 ;D or N snb radixHex mov w, #16 ;H snb radixBin mov w, #2 ;B or N snb radixDec rl radix ;if both .0 and .1 were set radix = 4 ;if only .1 was set radix = 10 Answer3 clrb radix.6 dec radix ;B=2,D=5,H=8,O=15 clc rr radix ;B=1,D=2,H=4,O=7 dec radix ;B=0,D=1,H=3,O=6 clb radix.2 ;B=0,D=1,H=3,O=2 -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Nikolai Golovchenko Sent: Wednesday, December 13, 2000 21:57 To: PICLIST@MITVMA.MIT.EDU Subject: Re: [SX]: Code challenge Parsing the radix from "B" for binary, etc.. James wrote: > mov w, #-63 > add fr, w > rr fr > mov w, #2 > snb fr.3 > mov w, #8 > snb fr.1 > mov w, #10 > snb fr.2 > mov w, #16 Or, ;B 01000010 ;O 01001111 ;D 01000100 ;H 01001000 ;Then increment: ;B 01000011 ;O 01010000 ;D 01000101 ;H 01001001 inc fr mov w, #2 snb fr.4 mov w, #8 snb fr.2 mov w, #10 snb fr.3 mov w, #16 Two instructions less :) Nikolai -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics