mercredi 10 juillet 2019

Converting Decimal to Binary/Bitshifting

[enter image description here][1]Okay, quick notice, this is a lab for my class, and I am by no means requesting answers for the entire lab, only a certain section because I have tried everything I can think of but it's not working. I am asking about the PRINT function. The only reason I provided the entire lab was to give you context so you are not completely confused.

So I believe I need to convert m_value to binary and then print. I can't just print out m_value, that just gives me an int. Now when I do just print the m_value, it is giving me the wrong int, because when I convert to binary the number doesn't match up with what the lab says it should. Also, I am aware that I haven't tried the for loop to space out the binary number. I would just like to get this step out of the way. It may have something to do with my TEST function but I asked my TA and he said it looked fine. I really am stumped on where to go next if anyone could help.

https://i.stack.imgur.com/UZt9i.png My lab

https://i.stack.imgur.com/d3fGO.png My code

 void Bitset::print() const {

//  printf("test\n");
//  printf("test\n");


 /*  if(m_value / 2 != 0) {
     ( m_value /2);
     }
 */
printf("%lu" , m_value);

 }

I would like the output to be like the lab says under the print section.

Aucun commentaire:

Enregistrer un commentaire