Steve Hicks (N5AC)

11-10-2006, 11:35 AM

I really like numbers.spin.· It is a real work of art!· I have been using it to display numbers, but I'm having trouble getting rid of the leading space for positive numbers.· Upon investigation, it appears that there is a mandatory sign character on the front of a string created with ToStr -- if the number is positive and no display of a sign is selected in the config, it·places a space on the front of the string instead.· I prefer, however,·to not have anything on the front of the number if it is positive and I've not selected a sign.· I made a slight modification to the internal routine, BCXToText as shown below that accomplishes this.· Just in case someone else has the same desire...· Just replace this one routine in your numbers.spin file·or you can use·the attached modified numbers.spin file.

PRI BCXToText(IChar, Grouping, ShowPlus, SPad, Field, Digits): Size | Idx, GCnt, SChar, GChar, X

'Convert BCX Buffer contents to z-string at StrBuf.

'IChar..Field each correspond to elements of Format. See "FORMAT SYNTAX" for more information.

'If Field = 0, Digits+1+Grouping is the effective field (always limited to max of 49).

'Digits : Number of significant digits (not counting zero-left-padding).

'RETURNS: Actual Size (length) of output string, not including null terminator.

SChar := "+" + 2*(BCX3 >> 28) + 11*(not (ShowPlus | (BCX3 >> 28)) or ((Digits == 1) and (BCX0 == 0))) 'Determine sign character ('+', ' ' or '-')

X := -(SChar <> " ")-(IChar > 0) 'Xtra char count (0, 1 or 2, for sign and optional base indicator)

IChar := Symbols[--IChar] 'Get base indicator character

GChar := Symbols[Grouping & 7 - 1 #> 0] 'Get group character

if Field > 0 and SPad^1 and Digits < 32 'Need to add extra zero-padding?

BCX3 &= $0FFFFFFF ' then clear negative flag and set to 32 digits

Digits := 32

Grouping := -((Grouping >>= 3) - (Grouping > 0))*(Grouping+1 < Digits) 'Get group size (0 if not enough Digits)

Size := (Field - (Field==0)*(Digits+X+((Digits-1)/Grouping))) <# 49 'Field = 0? Set Size to Digits+X+Grouping (max 49).

if Grouping 'Insert group chars

bytefill(@StrBuf+(Size-Digits-(Digits-1)/Grouping #> 2), GChar, Digits+(Digits-1)/Grouping <# Size-4)

Idx~~ 'Insert digits

repeat while (++Idx < Digits) and (Idx + (GCnt := Idx/Grouping) < Size-X)

byte[@StrBuf][Size-Idx-1-GCnt] := lookupz(byte[@BCX0][Idx>>1] >> (4 * Idx&1) // 16: "0".."9","A".."F")

bytefill(@StrBuf, " ", Size-Idx-(Idx-1)/Grouping #> 0) 'Left pad with spaces, if necessary

IF SChar <> " "

byte[@StrBuf][Size-X-Idx-(Idx-1)/Grouping #> 0] := SChar 'Insert sign

if X == 2

byte[@StrBuf][Size-1-Idx-(Idx-1)/Grouping #> 1] := IChar 'Insert base indicator, if necessary

byte[@StrBuf][Size] := 0 'Zero-terminate string

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Steve, N5AC

Post Edited (Steve Hicks (N5AC)) : 11/10/2006 3:57:18 AM GMT

PRI BCXToText(IChar, Grouping, ShowPlus, SPad, Field, Digits): Size | Idx, GCnt, SChar, GChar, X

'Convert BCX Buffer contents to z-string at StrBuf.

'IChar..Field each correspond to elements of Format. See "FORMAT SYNTAX" for more information.

'If Field = 0, Digits+1+Grouping is the effective field (always limited to max of 49).

'Digits : Number of significant digits (not counting zero-left-padding).

'RETURNS: Actual Size (length) of output string, not including null terminator.

SChar := "+" + 2*(BCX3 >> 28) + 11*(not (ShowPlus | (BCX3 >> 28)) or ((Digits == 1) and (BCX0 == 0))) 'Determine sign character ('+', ' ' or '-')

X := -(SChar <> " ")-(IChar > 0) 'Xtra char count (0, 1 or 2, for sign and optional base indicator)

IChar := Symbols[--IChar] 'Get base indicator character

GChar := Symbols[Grouping & 7 - 1 #> 0] 'Get group character

if Field > 0 and SPad^1 and Digits < 32 'Need to add extra zero-padding?

BCX3 &= $0FFFFFFF ' then clear negative flag and set to 32 digits

Digits := 32

Grouping := -((Grouping >>= 3) - (Grouping > 0))*(Grouping+1 < Digits) 'Get group size (0 if not enough Digits)

Size := (Field - (Field==0)*(Digits+X+((Digits-1)/Grouping))) <# 49 'Field = 0? Set Size to Digits+X+Grouping (max 49).

if Grouping 'Insert group chars

bytefill(@StrBuf+(Size-Digits-(Digits-1)/Grouping #> 2), GChar, Digits+(Digits-1)/Grouping <# Size-4)

Idx~~ 'Insert digits

repeat while (++Idx < Digits) and (Idx + (GCnt := Idx/Grouping) < Size-X)

byte[@StrBuf][Size-Idx-1-GCnt] := lookupz(byte[@BCX0][Idx>>1] >> (4 * Idx&1) // 16: "0".."9","A".."F")

bytefill(@StrBuf, " ", Size-Idx-(Idx-1)/Grouping #> 0) 'Left pad with spaces, if necessary

IF SChar <> " "

byte[@StrBuf][Size-X-Idx-(Idx-1)/Grouping #> 0] := SChar 'Insert sign

if X == 2

byte[@StrBuf][Size-1-Idx-(Idx-1)/Grouping #> 1] := IChar 'Insert base indicator, if necessary

byte[@StrBuf][Size] := 0 'Zero-terminate string

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Steve, N5AC

Post Edited (Steve Hicks (N5AC)) : 11/10/2006 3:57:18 AM GMT