How to convert a string into integers (in MIPS)

  • Thread starter Rat_Rodz
  • Start date
  • #1
Rat_Rodz
1
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.
 

Answers and Replies

  • #2
chiro
Science Advisor
4,815
134
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.
 

Suggested for: How to convert a string into integers (in MIPS)

  • Last Post
Replies
34
Views
340
Replies
2
Views
315
  • Last Post
Replies
13
Views
922
Replies
5
Views
354
Replies
18
Views
983
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
3
Views
864
Replies
4
Views
615
  • Last Post
Replies
14
Views
486
Top