Binary to Decimal Converter
Author |
Message |
WhatDotColourMaster
|
Posted: 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
|
|
|
[Gandalf]
|
Posted: 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
|
Posted: 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
|
Posted: 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?
**EDIT**
for adding number onto a variable, instead of doing this...
code: | number := number + 1 |
do this...
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. |
|
|
|
|
|
|
|