answersLogoWhite

0

AllQ&AStudy Guides
Best answer

unsigned binary_to_gray (unsigned num) {

return num ^ (num >> 1);

}

unsigned gray_to_binary (unsigned num) {

/* note: assumes num is no more than 32-bits in length */

num ^= (num >> 16);

num ^= (num >> 8);

num ^= (num >> 4);

num ^= (num >> 2);

num ^= (num >> 1);

return num ;

}

This answer is:
Related answers

unsigned binary_to_gray (unsigned num) {

return num ^ (num >> 1);

}

unsigned gray_to_binary (unsigned num) {

/* note: assumes num is no more than 32-bits in length */

num ^= (num >> 16);

num ^= (num >> 8);

num ^= (num >> 4);

num ^= (num >> 2);

num ^= (num >> 1);

return num ;

}

View page

num num num

View page

In simple Python code:

def convertToAngle(num):

while True:

if num < 0:

num = 360 - num

elif num > 360:

num -= 360

else:

break

return num

View page

#include<iostream>

#include<sstream>

#include<exception>

std::string decimal_to_roman (unsigned num) {

std::stringstream ss {};

while (num>0) {

if (num>10000)

throw std::range_error (

"ERROR: decimal_to_roman (unsigned num) [num is out of range]");

else if (num==10000) { ss<<"[M]"; num-=10000; }

else if (num>=9000) { ss<<"[CM]"; num-=9000; }

else if (num>=5000) { ss<<"[D]"; num-=5000; }

else if (num>=4000) { ss<<"[CD]"; num-=4000; }

else if (num>=1000) { ss<<"M"; num-=1000; }

else if (num>=900) { ss<<"CM"; num-=900; }

else if (num>=500) { ss<<"D"; num-=500; }

else if (num>=400) { ss<<"CD"; num-=400; }

else if (num>=100) { ss<<"C"; num-=100; }

else if (num>=90) { ss<<"XC"; num-=90; }

else if (num>=50) { ss<<"L"; num-=50; }

else if (num>=40) { ss<<"XL"; num-=40; }

else if (num>=10) { ss<<"X"; num-=10; }

else if (num==9) { ss<<"IX"; num-=9; }

else if (num>=5) { ss<<"V"; num-=5; }

else if (num==4) { ss<<"IV"; num-=4; }

else if (num>=1) { ss<<"I"; num-=1; }

}

return ss.str();

}

int main (void) {

for (unsigned n=1; n<=10000; ++n) {

try {

std::cout << n << "\t = " << decimal_to_roman(n) << std::endl;

}

catch (std::range_error& e) {

std::cerr<<e.what()<<std::endl;

break;

}

}

}

View page

num 1 is predator

num 2 is the beast

num 3 is mimi

num 4 is peachy

and num 5 is centi

View page
Featured study guide

That which slows the motion between two objects in contact with each other is defined as

Cesare Beccaria reviewed the political and emotional turmoil of the times with which of these writings

Castilian Grammar was one of the first books that recorded specific rules for which language

Large trucks sometimes have curved shields over their cabs to reduce

➡️
See all cards
No Reviews
More study guides
No Reviews

No Reviews
Search results