Need help converting bases with C++

Discussion in 'Programming and Homework Questions' started by Mastershroom, Jun 28, 2011.

Thread Status:
Not open for further replies.
  1. Mastershroom

    Mastershroom wat

    Reputations:
    3,833
    Messages:
    8,212
    Likes Received:
    16
    Trophy Points:
    206
    Not well enough to pass. :p

    In the end it's pretty much irrelevant at this point; I'm changing my major away from CS. Between this class and the other CS classes I took, I learned that it's really not for me. I haven't decided what I'm changing to yet, but it's a start. :p
     
  2. talin

    talin Notebook Prophet

    Reputations:
    4,694
    Messages:
    5,352
    Likes Received:
    2
    Trophy Points:
    205
    That's a pity, but best of luck in your new major (whatever it will be :p).
     
  3. redrazor11

    redrazor11 Formerly waterwizard11

    Reputations:
    771
    Messages:
    1,315
    Likes Received:
    0
    Trophy Points:
    55
    Goodluck with it. I've changed my major 3+ times but finally landed on CS. Only a year left till i get my B.S.

    Even if you don't study it anymore, the fundamentals of machine logic will help you in all areas of life. Especially videogames :p
     
  4. Zoran Horvat

    Zoran Horvat Newbie

    Reputations:
    0
    Messages:
    0
    Likes Received:
    0
    Trophy Points:
    0
    You can convert number in any base into any other base using this pseudocode:

    function ConvertNumber(number, b, d)
    begin
    newNumber = ""
    while number <> "0"
    begin
    number = Divide(number, b, d, out remainder)
    newDigit = ValueToDigit(remainder)
    newNumber = Concatenate(newDigit, newNumber)
    end
    if newNumber ="" then
    newNumber = "0"
    end

    function Divide(number, base, divisor, out remainder)
    begin
    remainder = 0
    result = ""
    for i = 0 to Length(number) - 1
    begin
    digitValue = DigitToValue(number)
    remainder = base * remainder + digitValue
    newDigitValue = remainder / divisor -- integer division
    remainder = remainder mod divisor
    if newDigitValue > 0 OR result <> "" then
    newDigit = ValueToDigit(newDigitValue)
    result = Concatenate(result, newDigit)
    end
    if result = "" then
    result = "0"
    return result
    end

    MOD EDIT: Don't link to your own website.
     
Loading...
Thread Status:
Not open for further replies.

Share This Page