How Do You Convert Decimal to Binary Using MIPS Code?

  • Thread starter Thread starter hkboy123
  • Start date Start date
  • Tags Tags
    Binary Mips
AI Thread Summary
To write MIPS code for converting a decimal number to binary, it's important to understand that if the number is stored as a standard word-based integer, it is already in binary format in memory. The process involves extracting each bit from the integer and printing it. The suggested approach uses a loop to shift the integer right and apply a bitwise AND operation to isolate each bit. The pseudo-code outlines a method where an array or string is used to store the binary representation, with the right shift operator (>>) and bitwise AND being key operations. Adjustments can be made to the indexing to change the order of the output.
hkboy123
Messages
2
Reaction score
0
Hello. I was simply wondering if anyone has any idea on how to write a MIPS code to convert a decimal number to its binary number. Anyone can help me?
 
Technology news on Phys.org
hkboy123 said:
Hello. I was simply wondering if anyone has any idea on how to write a MIPS code to convert a decimal number to its binary number. Anyone can help me?

What is the memory representation of your number?
 
integer
 
hkboy123 said:
integer

If its a standard word based integer, it is already in binary form in memory, and all you have to do is to get each bit and print the value. I don't know the platform you are using so I'll do pseudo-code:

Assuming unsigned integer:

x = size of word in bits
For i = 0 to x-1
bitarray[x-i-1] = (Word Value >> i) AND 1
Next i

The >> is a right shift operator, and AND is a bitwise AND instruction, not the comparison operator.

Bitarray has an array containing each digit value from left to right as you would read it if it were printed. If you want it the other way just modify the index in the loop. What you would do instead of creating the array, you would basically allocate some space for a string and then the value of the jth character would be equal to:

string[j] = '0' + (((Word Value >> i) AND 1) AND 255).
 
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.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top