Help splitting a number into 2 parts
Oldbitcollector (Jeff)
Posts: 8,091
I need to split a number into 2 numbers.
Example: 52 becomes x:=5 and y:=2
I'm using decx from Simplenumbers to grab the whole number
with this: s:= SN.decx(second,2)
Can someone help me with a routine to split both sides into two
different numbers into x & y?
Thanks
OBC
(Here's the decx routine)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Example: 52 becomes x:=5 and y:=2
I'm using decx from Simplenumbers to grab the whole number
with this: s:= SN.decx(second,2)
Can someone help me with a routine to split both sides into two
different numbers into x & y?
Thanks
OBC
(Here's the decx routine)
PUB decx(value, digits) | div '' Returns pointer to zero-padded, signed-decimal string '' -- if value is negative, field width is digits+1 clrstr(@nstr, MAX_LEN) digits := 1 #> digits <# 10 if (value < 0) ' negative value? -value ' yes, make positive nstr[noparse][[/noparse]idx++] := "-" ' and print sign indicator div := 1_000_000_000 ' initialize divisor if digits < 10 ' less than 10 digits? repeat (10 - digits) ' yes, adjust divisor div /= 10 value //= (div * 10) ' truncate unused digits repeat digits nstr[noparse][[/noparse]idx++] := (value / div + "0") ' convert digit to ASCII value //= div ' update value div /= 10 ' update divisor return @nstr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Comments
x := v / 10
y := v // 10
or
v := string('52')
x := v[noparse][[/noparse] 0 ] - "0"
y := v[noparse][[/noparse] 1 ] - "0"
n := 52
x := n / 10
y := n // 10
or are you after something ore complicated ?
Am I wrong or:
x := N/10
y := N - (x*10)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
I suspect because it is returning a string. An easy way to convert it?
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!
Advertisement sponsored by dfletch:
Come and join us on the Propeller IRC channel for fast and easy help!
Channel: #propeller
Server: irc.freenode.net or freenode.net
If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS