About binary pay attention to every binary use modulo division is simpler
For example, 6 6/2=3... 0 l=1... . 1 1/2=0... 1
.So 6 into 2 base for 110
About octal also can be used to divide the
For example under 17 has to push to
About octal convert binary for 8 is 3 to the power of 2 so the octal number a single out except the remainder less than three filling zero 2 o
Such as transform 8 hexadecimal 17 into two hexadecimal calculated for 001111 will be zero in front of the last cut off the line
Hexadecimal similarly transform binary reserved four line
Hey hey, published for the first time also won't with mobile phones
CodePudding user response:
Fyi:# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String. H>
# include & lt; The locale. H>
Int main () {
Int I, v;
Char bs [33].
Char b [33];
Char hs [9].
Char h [9];
Char s [4];
Char * e;
//decimal integer binary string;
I=1024;
Ltoa (I, b, 2);
Sprintf (bs, "% 032 s", b);
Printf (" I=% d, bs=% s \ n ", I, bs);
//decimal integer hexadecimal string;
I=1024;
Ltoa (I, h, 16);
Sprintf (hs, "% s" 08, h);
Printf (" I=% d, hs=% s \ n ", I, hs);
//hex string converted to a decimal number
Strcpy (hs, "00000400");
Sscanf (hs, "% x", & amp; I);
Printf (" the hs=% s, I=% d \ n ", the hs, I);
//binary string into hexadecimal string;
Strcpy (bs, "00000000000000000000010000000000");
I=strtol (bs, & amp; E, 2);
Ltoa (I, h, 16);
Sprintf (hs, "% s" 08, h);
Printf (" bs=% s, hs=% s \ n ", bs, hs);
//binary string converted to a decimal number;
Strcpy (bs, "00000000000000000000010000000000");
I=strtol (bs, & amp; E, 2);
Printf (" bs=% s, I=% d \ n ", bs, I);
//hex string into a binary string
Strcpy (hs, "00000400");
Sscanf (hs, "% x", & amp; I);
Ltoa (I, b, 2);
Sprintf (bs, "% 032 s", b);
Printf (" the hs=% s, bs=% s \ n ", hs, bs);
//ASC \ GBK string hexadecimal string
Strcpy (s, "a han");
i=0;
While (1) {
If (0==s [I]) break;
Sprintf (hs + I * 2, 02 x %, (unsigned char) s [I]);
i++;
}
The setlocale (LC_ALL, "CHS");
Printf (" s=% s, hs=% s \ n ", s, hs);
//hex string into (GBK Chinese characters) and characters (ASC)
Strcpy (hs, "61 baba");
i=0;
While (1) {
If (1!=sscanf (hs + I * 2, "% 2 x", & amp; V)) break;
S [I]=(char) v.
i++;
}
S [I]=0;
Printf (" the hs=% s, s=% s \ n ", hs, s);
return 0;
}
//I=1024, bs=00000000000000000000010000000000
//I=1024, hs=00000400
//hs=00000400, I=1024
//bs=00000000000000000000010000000000, hs=00000400
//bs=00000000000000000000010000000000, I=1024
//hs=00000400, bs=00000000000000000000010000000000
//s=a han, hs=61 baba
//hs=61 baba, s=a han
CodePudding user response:
With a calculator, the most simpleCodePudding user response:
8 hexadecimal turn 2 base: because a 8 hexadecimal Numbers corresponding to the three 2 into the system, so each one 8 hexadecimal number is converted directly, for example: 8 hexadecimal 175 converted to hexadecimal1 7 5
001 111 101
The result is
001111101
Usually 0 can be removed at the front of the
Also written as
1111101,
Similarly, 2 hexadecimal turn 8 hexadecimal, in turn, starting from the decimal point three 1 group,
1 111 101
1 7 5
Again by the same token, the 2 base and hexadecimal, 1 group and the difference between a front is four
CodePudding user response:
Exam is fine. Really programmers must use calculatorCodePudding user response: