Jump to content

Printing multi digit decimal representation of a byte in Brainfuck

- - - - -

  • Please log in to reply
5 replies to this topic

#1
minime12358

minime12358

    Newbie

  • Members
  • Pip
  • 1 posts
Hi,

I know brainfuck is not assembly, however i figured it is close enough :P

I was basically just wondering if anyone had an idea on how to print a multi digit representation of a byte in brainfuck (As in a byte that is 241 will print "241")

Thanks :)

#2
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
This doesn't answer your question, but you may find this and this interesting. I just simply don't feel like writing a program to do this at the moment, maybe I will feel like it later. Here may be a basic layout of how the program will go, though:
Use that "divmod" algorithm found at the bottom of the second page to divide by 10 and mod by 10 at the same time. On the first run through, the output of mod 10 will be the first digit to the right (eg for your case '1'). Then you run the algorithm on the original number divided by 10, and use the mod 10 output as the next digit from the right (in your case '4'). You would want to use a loop that would run until the divide by 10 output is zero. Which, of course, can only be up to 3 iterations of the loop for brainfuck.

Also, this forum probably wasn't the best place to ask this question. I couldn't say where you should have posted though.
Latinamne loqueris?

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
@minime12358: brain-what? I thought that was a bad word. It should probably rather be called brain* , I think.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
@Rhetorical: That's the name of a language that was basically designed to be a nightmare to program in, or very close to a Turing Machine, depending on your perspective.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
I take the second perspective :D
Latinamne loqueris?

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript

mebob said:

Also, this forum probably wasn't the best place to ask this question. I couldn't say where you should have posted though.

The General Programming forum.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users