# SXMicrocontroller Radix MathMethod

## Parsing the radix from "B" for binary, 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	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
```

See also:

 file: /Techref/scenix/lib/math/radix/parseradix-jn_sx.htm, 1KB, , updated: 2004/6/10 13:40, local time: 2020/11/29 13:56, TOP NEW HELP FIND:  3.238.107.166:LOG IN

 ©2020 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?Please DO link to this page! Digg it! / MAKE! Parsing the radix from "B" for binary, etc..

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here:
if you want a response, please enter your email address:
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2020 contributors: o List host: MIT, Site host massmind.org, Top posters @20201129 Bob Blick, RussellMc, madscientistatlarge, Neil, Jason White, James Cameron, David C Brown, Sean Breheny, Harold Hallikainen, Alan Pearce, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.