Re: Euler Project Problems.
John Rible <[email protected]> Mon, 19 May 2008 23:44:50 -0700
| Newsgroups | gmane.comp.lang.forth.colorforth |
|---|---|
| Message-ID | <[email protected]> |
Ray St. Marie wrote: > Dear Albert, > > I added a " dup ." after C@ below just to see what was being sent to > the word ASCII->BINARY. > Using the "FACTORISE 123456" example DUP . prints 49 144 which I find > odd because I only asked to print one number after C@ which I assume > is 49, but then I suppose that makes 144 one of the factors. I could > be wrong and often am. > > : READ.DECIMAL.NUMBER \ ( --- >> "number.string" ) > 1 TO PRECISION \ Reset precision > BL WORD \ get from input > COUNT \ String.address length > DUP 0= ABORT" Please input a number" > DUP length ! \ Remember! > 0 DO \ Convert each digit > C@ dup . \ C@+ is this a typing error? RAS 080519 no, the C@+ is correct (most systems have it defined) : C@+ ( ca -- ca+ char ) COUNT ; \ or " dup 1 chars + swap c@ " > ASCII->BINARY > I num digit! \ to binary in number. > LOOP DROP \ Drop string address. > 10 current.base digit! \ Start with decimal > 0 current.base CELL+ ! \ Guard decimal for the overflow > ; > And from the code around it in READ.DECIMAL.NUMBER, ASCII->BINARY should return a single integer. So it's the comment that is wrong, not the code. That always gives me a bad feeling. Good hunting! -John