How to print a number in bf?

Add a reply

Posted by rretzbach 1393 days ago:
Hi,

I just wanted to write a little bf program to ease my boring life at work :D
So I decided to calculate the square of a given number.
Now I _only_ need to ouput this number.

The number could be larger than 8bit with my bf interpreter, so I need a clever algo to ouput a multi-char number.
I thought of many ways, but now it fails I can't store all chars sequentially without predefining how large it has to be.

Maybe someone can point me in a direction. I googled hard.

My current approach was:

lets say we have 144 as number we want to print to the screen.

subtract 10 and count how often you subtract 10 from the number until the remaining number is less than 10 (I coded this part already)
Then I thought of using a zero as delimiter between temp cells and the digit cells so that I can use [>] to find the place for the next digit (here I fail)

Help is appreciated, thanks.
I'll study the square example now.

Add a reply