a code

I want to write a code that prints a table of the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1 through 256.

anyone know that?

Comments

  • : I want to write a code that prints a table of the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1 through 256.
    :
    : anyone know that?
    :
    [green]
    Dude, your going to PO some people on this board if you don't stop asking questions like that. People are to help not give you code to every little homework assignment.
    [/green]

  • : I want to write a code that prints a table of the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1 through 256.
    :
    : anyone know that?
    :

    look up the options for the printf() function, such as "%d" is decimal value. Read the docs carefully and it will give you the answer to your question.
  • : I want to write a code that prints a table of the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1 through 256.
    :
    : anyone know that?
    :


    print out a table header if desired

    loop(...){

    %o for octal
    %x or %X for hex

    }

    Lord help you when it comes to the binary part. :p
  • The most good-looking implementation of that would be based on the fact that each digit in any of those numbers can be expressed as

    number[0]*base^0 + number[1]*base^1 + ... + number[n]*base^n

    where n is the index of the most significant digit.


    Some examples

    Binary: 1010 (base 2)
    Decimal equivalent = 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 = 10

    Hex: AF (base 16)
    Decimal equivalent = 10*16^1 + 15*16^0 = 175


    This is also very fundamental knowledge to a programmer, sence this is how you calculate those strange numbers without a calculator in sight :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories