Computer Science Canada

very basic decimal --> binary converter

Author:  ZeroPaladn [ Tue Sep 20, 2005 1:05 pm ]
Post subject:  very basic decimal --> binary converter

this is my basic decimal to binary converter. im working on a way to go backwards from binary to decimal. its not very user friendly, but hey, whatever.

Author:  Mr. T [ Tue Sep 20, 2005 4:44 pm ]
Post subject:  Alex's Opinion

Good effort.

Author:  ZeroPaladn [ Wed Sep 21, 2005 7:08 am ]
Post subject: 

thanks. im going to post the other half of the program (binary --> decimal) later on either today or tomorow when i get to finishing it.

Author:  codemage [ Thu Sep 22, 2005 1:07 pm ]
Post subject: 

If this is for school, you'd get brownie points for throwing in hex conversion as well.

binary -> hex -> binary is the easiest conversion of all 3.
Once you have that down, you can 'cheat' by converting

decimal -> binary -> hex
or
hex -> binary -> decimal

...for conversion between all three.

Author:  ZeroPaladn [ Thu Sep 22, 2005 1:33 pm ]
Post subject: 

lolz, yeah but i prefer a challenge instead of going hex/bin. then again, nobody said bin/dec was hard...


Ill do it.

Author:  zylum [ Thu Sep 22, 2005 5:49 pm ]
Post subject: 

behold... a function that has the ability to convert from any base to any other base in 1 line of code (minus the function declaration):

code:
fcn baseConverter (x : string, initialBase, resultBase : int) : string
    result intstr ((strint (x, initialBase)), 0, resultBase)
end baseConverter


Laughing

Author:  ZeroPaladn [ Fri Sep 23, 2005 8:57 am ]
Post subject: 

HOLY F***ING S***! sorry for caps but i was going to create a function for each thing (ex binary2hex, binary2decimal, you get the idea), but, wow. Thanks alot zylum

+bits

Author:  [Gandalf] [ Fri Sep 23, 2005 3:05 pm ]
Post subject: 

Quote:
+bits

It just so happens that he is a moderator, and +bits will do nothing, but it's the thought that counts Wink.

I am pretty sure your teacher would be happier if you did the conversions using the method you learned, not (basically) a function that already exists to do it. Sure, "don't recreate something if there's an existing library function to do it for you", but there's also the learning process.

Author:  ZeroPaladn [ Mon Sep 26, 2005 11:03 am ]
Post subject: 

lolz, attempting to do waht zylum suggested is harder than i though, so i stuck with the old idea that i had. Lolz, it wouldnt let me give him bits anyways... Embarassed

Author:  Mr. T [ Tue Sep 27, 2005 8:12 pm ]
Post subject:  Alex's Opinion

ZeroPaladn wrote:
Lolz, it wouldnt let me give him bits anyways... Embarassed

Mod bit totals are fixed. Rolling Eyes

Author:  Cervantes [ Tue Sep 27, 2005 9:37 pm ]
Post subject:  Re: Alex's Opinion

Pwned wrote:
ZeroPaladn wrote:
Lolz, it wouldnt let me give him bits anyways... Embarassed

Mod bit totals are fixed. Rolling Eyes

By which he means the whole donation-modding-of-bits is bugged right now. You can still give bits to mods. The difference is our bits go back to 1000 the next time we post.

Author:  ZeroPaladn [ Wed Sep 28, 2005 8:32 am ]
Post subject: 

lolz, you learn sumthing every day now dont we? Rolling Eyes

EDIT

I didnt know zylum was a mod, grats

Author:  beard0 [ Wed Sep 28, 2005 4:37 pm ]
Post subject: 

ZeroPaladn wrote:
I didnt know zylum was a mod, grats

If someone has 1000 bits exactly, chances are pretty darn good that that person is a mod.

Author:  wtd [ Thu Sep 29, 2005 12:47 pm ]
Post subject: 

ZeroPaladn wrote:
I didnt know zylum was a mod, grats


He's a stealth mod. Wink

Not that I would know anything about that...

Author:  [Gandalf] [ Thu Sep 29, 2005 2:45 pm ]
Post subject: 

Quote:
zylum
Moderator
Kick Ass Hacker

Not very stealthy anymore, is he? Surprised

Author:  ZeroPaladn [ Fri Sep 30, 2005 11:10 am ]
Post subject: 

this is what i get for not being on compsci for the entire summer... anyways, i've yet to get much work done on the project, mainly cause its all math (aaaaarrrrrgggggghhhhh!) slowly but surely, its coming tho.

Author:  [Gandalf] [ Fri Sep 30, 2005 7:34 pm ]
Post subject: 

Did you get something like so:
code:
var inputNum : int
var binaryOut : array 1 .. 8 of int := init (0, 0, 0, 0, 0, 0, 0, 0)

get inputNum

for count : 1 .. 8
    if inputNum mod 2 = 1 then
        binaryOut (count) := 1
    else
        binaryOut (count) := 0
    end if
    inputNum := inputNum div 2
end for

for decreasing count : 8 .. 1
    put binaryOut (count) ..
end for


Oops, wrong thread, but it's about the same thing anyway Surprised.


: