Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Printing multi digit decimal representation of a byte in Brainfuck

printing

  • Please log in to reply
5 replies to this topic

#1 minime12358

minime12358

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 10 October 2011 - 05:51 PM

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 :)
  • 0

#2 mebob

mebob

    CC Devotee

  • Validating
  • PipPipPipPipPipPip
  • 467 posts
  • Programming Language:C, C++, Assembly
  • Learning:PHP

Posted 11 October 2011 - 12:05 PM

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.
  • 0
Latinamne loqueris?

#3 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 11 October 2011 - 03:02 PM

@minime12358: brain-what? I thought that was a bad word. It should probably rather be called brain* , I think.
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 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

Posted 11 October 2011 - 06:38 PM

@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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 mebob

mebob

    CC Devotee

  • Validating
  • PipPipPipPipPipPip
  • 467 posts
  • Programming Language:C, C++, Assembly
  • Learning:PHP

Posted 12 October 2011 - 03:16 PM

I take the second perspective :D
  • 0
Latinamne loqueris?

#6 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 19 October 2011 - 01:48 PM

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.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download