Krepta, et al --

...and then Aaron Ingebrigtsen said...
% 
% >This is a terrible way to do it. Does QBasic support the modulus operator,
% >commonly written as "mod" (in Pascal) or '%' (in C-style languages), where
% >"x % y" returns the remainder when x is divided by y?
% 
% I don't know of one.  QBasic is pretty basic in it's commands and 
% operators. I've tried writing a QBasic program that does this, but I just 
%  can't get it right.  I first start out by determining if the Decimal number 
% is Even or ODD, that way I already know that the last character in the 
% Binary conversion will either be a 1 or a 0.  Then if the DEC number is 
% ODD, I simply remove 1 from it to make it even, then perform an operation 
% on that even number to try to determine the largest subtractable number in 
% Binary, then I subract that number, adding a 1 to the binary number, and 
% try again to find the highest subractable number, and so on, until I finaly 
% reach the smallest subractable number in binary and get done with the 
% calculation.  What I'm haveing trouble with is keeping track of the 1s and 
% 0s in binary.  This QBasic language is really giving me a headache, but its 
% the only language I know.

Why worry about the even-ness or the odd-ness at all?  Just let recursion
handle the end just like it does the middle.

  input output
  469   256 (100000000) + 213
  213   128 (010000000) + 85
   85    64 (001000000) + 21
   21    16 (000010000) + 5
    5     4 (000000100) + 1
    1     1 (000000001)

  RESULT     111010101


% 
% As for the XL spreadsheet, MAN was that easy to create. :)  It may not be 
% an APPLICATION writen in C++ or Java or something, but it gets the job done 
% VERY easily both on the computer, and on paper. :)

Assuming you have a machine with enough wasted RAM and a license for
Excel ;-)


% 
...
% >arbitrary base conversion programs that simply use the modulus and
% >exponentiation in a loop to do the conversion. The idea is something like
% >this:
% 
% I don't understand how you would use the remainder for anything.  In basic 
% the remainder isn't seperate from the rest of the number, and a number with 
% a remainder is very hard to work with, mathematicaly.  So I'd rather just 
% eliminate the remainder, or ODDness of the number. :)

See above for an example.


% 
% >
% >while (number greater than zero) {
% >     find current digit
% >     subtract current digit value from number
% >     increment a counter
% >}

Hey, that looks familiar :-)


% I use a counter in my QBasic file, incrementing until the number it
% generates is larger than the number to be converted, or the remaining

Good!


% amount to be converted, then going back a step to the previous
% incremement,

Makes sense.


% subtracting THAT incremented number from the number to be converted and
% adding a 1 to the binary number and changing the number to be worked on
% to
% find out the Next highest possible subtractable number, and so on.  I'm
% just having difficulty telling it how many 0s to put between the 1s.
% GRRR!!!

Simple; when you back down a step (like from 64 to 16, going thru 32,
above) and have to skip that position because half is still too big, tell
your code to spit out a zero right then just like you'd tell it to spit
out a one if you *could* subtract 32.


HTH & HAND

:-D
-- 
David T-G                      * It's easier to fight for one's principles
(play) davidtg at justpickone.org * than to live up to them. -- fortune cookie
(work) davidtgwork at justpickone.org
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/chat/attachments/20020401/9428af66/attachment.pgp>

Reply via email to