solve problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsingh
    New Member
    • Mar 2008
    • 1

    solve problem

    HI guies can u help me to solve this problem.
    Code:
    Write a program that prints a table of the binary equivalents of the decimal numbers in the range 1 through 256.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • Sick0Fant
      New Member
      • Feb 2008
      • 121

      #3
      I can say with total confidence that it is unsolvable. There is an infinity of numbers between any two decimal numbers, so it's unlikely you'll ever print them all.

      Now, if you meant integers ...

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        You need to write a function which will convert a positive integer into its binary equivalent and then a main() test driver to test the function with various input. Can you manually convert from base 10 to base 2 ? (dec to bin)
        e.g. Using base 10 176 comprises 6 1`s + 7 10`s + 1 100 = 6+70 +100=176
        So the columns are ........etc. 100000 10000 1000 100 10 1
        Using base 2 the colums are multples of 2 instead of 10
        ............... ............... .......etc.1024 512 256 128 64 32 16 8 4 2 1
        so a binary number like 1 0 1 1 0 1 0 1 1 0 0
        would equal 1024 + 256+128 + 32 + 8+ 4 = 1452

        and 176 to base 10 = 0 1 0 1 1 0 0 0 0 in binary
        From the above you may be able to develop the required algorithn on which to base your code.
        Sorry i couldn`t keep the columns lined up!

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by whodgson
          Sorry i couldn`t keep the columns lined up!
          It is difficult, but I find putting things in code tags helps. Just something to consider if you really need to show formatted data in the future.

          Comment

          • whodgson
            Contributor
            • Jan 2007
            • 542

            #6
            Thanks......... .. will do.

            Comment

            Working...