2.3 Binary Conversions
When you use int to save an integer. The memory is stored in binary, when it is to be displayed. displayed in decimal.
Conversion between random conversions
N-in-turn M-binary
String s = "2001201102"
3 binary conversion to 5 binary
Convert to 2 binary first. Convert to 5 binary
/* Random binary conversion n-binary to M-binary string s = "2001201102" 3 conversion to 5-binary first converted to 10-binary, then to 5 */package Binarytrans; public class Ntom {public static void Main (string[] args) { String s = "2001201102";//three-binary string int Startsystem = 3; int endsystem = 5; The binary string is converted to true value, and int n = 0 is displayed in decimal. for (int i=0;i<s.length (); i++) { char c = s.charat (i); n = n*startsystem + (c-' 0 ');//convert the binary to decimal, 10 bits: one when three}/ / * n=14235; n%-->5 n = n/10; n%-->3 n = n/10 ... */ String s2 = ""; while (true) { s2 = n%endsystem + s2;//Five-binary conversion n = n/endsystem; if (n==0) break; } SYSTEM.OUT.PRINTLN (s2); }}
2244434
ExcelCell Conversions
Excel cell addresses are available in two formats:
Common formats, such as: A5, BC12
Corresponding RC format: R5C1, R12c55
Obviously, the RC format is given directly to travel and column numbers
Please program the conversion between the two address formats.
/*excel cell conversion Excel cell address has two formats: normal format. such as: A5, BC12 the corresponding RC format: R5C1, R12c55 obviously. The RC format is direct to the travel number and the column number programmed between the two address formats to be converted. */public class Exceltranslation {public static void main (string[] args) {String s = "BC12"; System.out.println (s); System.out.println (NORMALTORC (s)); String s2 = "R5C1"; SYSTEM.OUT.PRINTLN (S2); System.out.println (Rctonormal (S2)); The//RC mode is changed to normal mode public static string Rctonormal (string s) {s=s.substring (1);//will start R minus String ss[] = S. Split ("C");//C-cut string int column = Integer.valueof (ss[1]);//Convert column number to Truth (decimal) String s2 = ""; while (true) {s2 = (char) (column%26 + +) + s2;//back to 26 binary. Output char type letter column = COLUMN/26; if (column==0) break; String result = S2+ss[0]; return result; }//Normal mode to RC mode public static String Normaltorc (string s) {int start_digit = 0;//number initial position for (int i=0;i <s.length (); i++) {//traverse the string to find the cut point if (Character.isdigit (S.charat (i))) {//Get the position where the number appears I start_digit=i; break;//jumps out, avoids the second occurrence of the number}} string column = S.substring (0, start_digit);//Gets the letter, that is, the column number (26 binary) string row = s.substring (start_digit);//Get number, line number//convert 26 binary to decimal int n=0; for (int i=0;i<column.length (); i++) {char c = column.charat (i);//Get each letter N = n*26 + (c-64);//convert 26 binary As decimal, ' A ' -64=1} String resultrc = "R" +row+ "C" +n; return RESULTRC; }}
Bc12r12c55r5c1a5
Programming algorithm Basics-2.3 binary conversions