How to convert a string into integers (in MIPS)

  • Thread starter Rat_Rodz
  • Start date
  • #1
1
0

Main Question or Discussion Point

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.
 

Answers and Replies

  • #2
chiro
Science Advisor
4,790
131
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 lets 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.
 

Related Threads on How to convert a string into integers (in MIPS)

Replies
1
Views
6K
Replies
1
Views
7K
Replies
6
Views
5K
Replies
3
Views
13K
  • Last Post
Replies
2
Views
3K
Replies
1
Views
11K
Replies
3
Views
557
Replies
5
Views
7K
  • Last Post
Replies
16
Views
7K
Top