;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 radix.0, binary jb radix.1, decimal jb radix.2, hex jb radix.3, 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
file: /Techref/scenix/lib/math/radix/parseradix-jn_sx.htm, 1KB, , updated: 2004/6/10 13:40, local time: 2024/11/24 21:56,
3.143.241.253:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/scenix/lib/math/radix/parseradix-jn_sx.htm"> Parsing the radix from "B" for binary, etc..</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.