5621 the method for converting to a hexadecimal number is the "except for the remainder of 16" method, 5621/16 = Shang 351 more than 5, the last digit of the hexadecimal system is 5 351/16 = Shang 21 more 15, the second digit on the right of the hexadecimal system is f 21/16 = Shang 1 more than 5, and the third digit on the right of the hexadecimal system is 5 1/16 = Merchant 0 more than hexadecimal number the fourth to the right is 1 merchant 0 will not continue
The final result is 15f5.
# Include <iostream> # include <string> using namespace STD; // convert an integer to a string int2str (INT num); int main (INT argc, char * argv []) {// convert decimal to hexadecimal int num = 0; cout <"Please input a num" <Endl; CIN> num; string str_num; while (Num/16! = 0) {int A = num/16; int mod_a = num % 16; cout <"mod_a =" <mod_a <Endl; string s; Switch (mod_a) {case 10: S = 'a'; break; Case 11: S = 'B'; break; Case 12: S = 'C'; break; Case 13: S = 'D'; break; Case 14: S = 'E'; break; Case 15: S = 'F'; break; default: S = int2str (mod_a ); break;} str_num = S + str_num; num = A;} If (Num % 16! = 0) {int last_a = num % 16; str_num = int2str (last_a) + str_num;} cout <"the hex num =" <str_num <Endl; return 0;} string int2str (INT num) {If (num = 0) Return "0"; string STR = ""; int num _ = num> 0? Num:-1 * num; while (Num _) {STR = (char) (Num _ % 10 + 48) + STR; num _/= 10 ;} if (Num <0) STR = "-" + STR; return STR ;}