I have an assignment to create a program that will add two Binary Numbers.
I can assume that both numbers are of the same length, and that both are
binary in the form of {Add [0 1 0 1 1 0] [0 0 1 0 1 1]}.  I have developed a
program that will add the two numbers together, but it doesn't give me a
binary result.  I need to write another function that will deal with adding
the two numbers and the carry over.  It is the Carry over I'm having trouble
with.  I can grasp how the program I wrote manipulates the stack, but i'm
not sure how the new function will throw the carry over into the preceding
stack result and then add them again.

Can anyone help me.  I would prefer to not be given the answer right yet,
but at least help lead me in the right direction.  Here is what I have so
far.

declare
fun {Add B1 B2}
   if {Length B1} == {Length B2} then
      case B1 of H1|T1 then
     case B2 of H2|T2 then
        H1 + H2|{Add T1 T2}
     end
      end
   else
      raise domainError(0)
      end
   end
end

declare
fun {AddDigits X Y C}
      if X + Y + C == 0 then 0 else 1 end
end

The AddDigits function is written to simply add H1 and H2 together and place
the result in the stack(it isn't finished yet, but this is a start and I
will build upon it to complete it)  I will replace the H1+H2|{Add T1 T2}
with {Adddigits X Y C}|{Add T1 T2} eventually.

I also know the AddDigits function needs to be a function within a function,
but i'm not sure how exactly it is to work.  Any help would be appreaciated.


One last thing about this forum, how do I reply to a thread I create if I
need more information?  I haven't figured that out yet either...


-- 
Kurt Breitsprecher
(807) 474-9601
[email protected]
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to