Arithmetic calculations!

Hello!

I have this assignment where I have to create a program that simulates a simple calculator (two operands, one operator: +, -, /, *, etc.)...
I have the math part covered, but I've got a few doubts about one other aspect of the coding:

The "calculator" must have four modes: Hex, decimal, octal and binary...
The user inputs the values according to the selected mode, they are then evaluated (to see if they fit within the selected mode) and the program goes on to perform the selected operation. Finally, it inputs the result in the selected mode...

Example:
Binary Mode:
0101 + 0001 = (values match bin. mode) Result: 0110

Octal Mode:
07 + 08 = (second value does not match) Result: "Input Error" Message

Is this algorithm correct?:
1. Receive values (strings)
2. Convert strings to decimal values and perform operations
3. Convert decimal values (results) to string according to selected mode
4. Output resulting value (string)

If this is correct, I may need some help with converting strings to decimal and viceversa... :)

Thanks in advance!

Comments

  • I may need some help with converting strings to decimal & viceversa. :)

    Procedures to get ASCII numbers from memory, convert to value,
    then convert & print. IN/OUT for Hex, Binary, Decimal,
    you could also add a string searcher that figgures out which is inputed
    hex,bin,dec ? Look for an 'h' ending, an 0x prefix for hex, 'b' ending for binary, etc.

    I have pre written Nasm converters in C:NASMINC16 in my
    http://bitdog.home.att.net/files/nasmenv.zip
    writdigt.inc wmemh.inc wmemhsp.inc etc
    gmemh.inc gmemb.inc ginnum.inc
    Procs start with G for Get, W for Write.
    MEM in the name, gets/puts to/from memory.
    Look around in the directory.
    A description & input/output is at the top of each proc.
    You will want to convert the addressing, header, & footer for your assembler?
    (If you're not using Nasm) (The nasmenv.zip is a meg)
    All my stuff is free, use it in any way you want.

    Bitdog

  • : I may need some help with converting strings to decimal & viceversa. :)
    :
    : Procedures to get ASCII numbers from memory, convert to value,
    : then convert & print. IN/OUT for Hex, Binary, Decimal,
    : you could also add a string searcher that figgures out which is inputed
    : hex,bin,dec ? Look for an 'h' ending, an 0x prefix for hex, 'b' ending for binary, etc.
    :
    : I have pre written Nasm converters in C:NASMINC16 in my
    : http://bitdog.home.att.net/files/nasmenv.zip
    : writdigt.inc wmemh.inc wmemhsp.inc etc
    : gmemh.inc gmemb.inc ginnum.inc
    : Procs start with G for Get, W for Write.
    : MEM in the name, gets/puts to/from memory.
    : Look around in the directory.
    : A description & input/output is at the top of each proc.
    : You will want to convert the addressing, header, & footer for your assembler?
    : (If you're not using Nasm) (The nasmenv.zip is a meg)
    : All my stuff is free, use it in any way you want.
    :
    : Bitdog
    :
    :


    I was thinking something along the lines of having the user select mode first (save it into a var.) and then write different procedures, according to which mode he chose, to convert the strings to values using a loop to detect and convert each character and adding it to the total...

    One process for binary mode, one or hex., etc.
    Then process the values and convert them back to strings (again, one proc. per mode)... Do you think that'll work?

    I'll take a look at the file you gave me... Thanks for the input! :)
  • The procs I have only do the conversion from ASCII to value in hex,binary,decimal and from value to ASCII.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories