Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Binary to Decimal Converter
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
WhatDotColourMaster




PostPosted: Sun Dec 04, 2005 8:54 pm   Post subject: Binary to Decimal Converter

Converts Decimal to Binary.....

code:
%************************************************************************************ ||
%* Author: WhatDotColour
%* Date: Sept, 24 2003
%* Purpose: To make a program that converts a binary number to decimal. *
%* Input: A binary number (int) *
%* Output: The program will output a integer (number in decimal format) *
%************************************************************************************

var intBinary : int
var intDigit : int
var intPower : int := 0
var intSum : int := 0

put "Please enter a Binary Digit."
get intBinary

loop
intDigit := intBinary mod 10
if intDigit = 1 then
intSum := intSum + (2 ** intPower)
end if
intPower := intPower + 1
intBinary := intBinary div 10
exit when intBinary = 0
end loop

put intSum


Just something I had lying around in my Turing Folder....
Any comments or improvements appreciated...
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Dec 04, 2005 9:29 pm   Post subject: (No subject)

Improvements? Well...
code:
intstr(decimalNumber, allocatedWidth, base)


Lets say... convert 12 to binary...
code:
put intstr(12, 8, 2)

Much easier, right?

And, please, indent!
WhatDotColourMaster




PostPosted: Mon Dec 05, 2005 3:24 pm   Post subject: (No subject)

Thanks Gandalf...i will indent from now on... and that is a better improvement. My aknowledgements to you and tony on my 255 colour code program.
ZeroPaladn




PostPosted: Wed Dec 07, 2005 10:08 am   Post subject: (No subject)

look at mine, theres lost of source code here to hlep you improve yours, including submissions by myself, [Gandalf], and others whom i cannot remember (the only reason why i remembered [Gandalf] is because he helped out the entire way for my program). hope this helps.

Wow, for once a legit program from you, or is this one taken as well? Shifty

**EDIT**

for adding number onto a variable, instead of doing this...
code:
number := number + 1

do this...
code:
number += 1

this can be used for subtraction as well, but im not sure if you can do this with multiplication or division.

**EDIT AGAIN**
http://www.compsci.ca/v2/viewtopic.php?t=9756&highlight=
i should post my url to my binary / decimal converter.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: