
-----------------------------------
WhatDotColourMaster
Sun Dec 04, 2005 8:54 pm

Binary to Decimal Converter
-----------------------------------
Converts Decimal to Binary.....

%************************************************************************************ || 
%* 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...

-----------------------------------
[Gandalf]
Sun Dec 04, 2005 9:29 pm


-----------------------------------
Improvements?  Well...
intstr(decimalNumber, allocatedWidth, base)

Lets say... convert 12 to binary...
put intstr(12, 8, 2)
Much easier, right?

And, please, indent!

-----------------------------------
WhatDotColourMaster
Mon Dec 05, 2005 3:24 pm


-----------------------------------
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
Wed Dec 07, 2005 10:08 am


-----------------------------------
look at mine, theres lost of source code here to hlep you improve yours, including submissions by myself, number := number + 1
do this...
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.
