How to convert a string into integers (in MIPS)

AI Thread Summary
To calculate the time difference between two military format times represented as strings, first ensure that the input strings are valid and contain only numeric characters. The conversion from string to integer can be achieved by iterating through the string from the end to the start. For each character, calculate its integer value by subtracting the character '0' from it, and multiply this value by 10 raised to the power of its position in the string. This method allows for the construction of the integer representation of the time, which can then be used to compute the difference between the two times.
Rat_Rodz
Messages
1
Reaction score
0
Hey,

I'm working on a project for my Computer Organization class and I have to read in 2 separate times (in military format with no ":" ) as strings and then find and print the time difference. I am able to read in and save the strings no problem, but I don't have a clue as to how I can manipulate them into integers. any suggestions? ...I would post the code that I have already, but I'm not sure as to how to go about it.
 
Technology news on Phys.org
Rat_Rodz said:
Hey,

I'm working on a project for my Computer Organization class and I have to read in 2 separate times (in military format with no ":" ) as strings and then find and print the time difference. I am able to read in and save the strings no problem, but I don't have a clue as to how I can manipulate them into integers. any suggestions? ...I would post the code that I have already, but I'm not sure as to how to go about it.

Hey Rat_Rodz and welcome to the forums.

The first thing to do is to make sure that the string is valid. For the moment let's assume that the string is required to be only in base 10 (ie only have characters '0' to '9').

So assuming we string has the correct format, the rest is pretty easy.

Going from end of string to start of string we start off with our temp variable to be zero.
For each character we do temp = temp + 10^(counter) * 'value of digit'.

The digit will be calculated by using the relationship 'value of digit' = 'char value' - '0'. counter will increment in a natural loop from 0 to string_len-1.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top