decimal to base 8 algorithm

This is a discussion on decimal to base 8 algorithm within the C Programming forums, part of the General Programming Boards category; I am trying to create a function inside my program that calculates a number in base 8(eg. 11 in base ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    23

    decimal to base 8 algorithm

    I am trying to create a function inside my program that calculates a number in base 8(eg. 11 in base 8 is 13), but I dont know how this conversion works. I just need the method conversion, the code I will write myself. Please explain. Thanks in advance.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You mean you want to output a number in base 8? You can do that with a loop that takes modulo of the base, displays the digit and divides teh remaining number by base, until there is nothing left of the number. Unfortunately, that gives you the number backwards, so you have to store the digits away and then write them out "last one first".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal out algorithm
    By rocketman50 in forum Tech Board
    Replies: 1
    Last Post: 02-28-2009, 05:42 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 03:52 AM
  4. Binary to Base 10 decimal conversion
    By JFonseka in forum C Programming
    Replies: 13
    Last Post: 11-20-2007, 03:14 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21