Decimal conversion issues

1.10 hex turn hex
    2591 converted to hexadecimal:
... + x2*16^2 + x1*16^1 + x0*16^0  =  2591
With mod16 get:
x0 = 2591 % 16 = 15   --->   x0 = 15
With divided by 16:
... + x2 * 16^1 + x1*16^0 = 161
Again with mod16:
x1 = 1
With divided by 16:
... + x2 * 16 ^ 0 = 10
mod again 16:
x2 = 10
Divided by 16:
The right hand of formula = 0, end of the calculation
After the conversion to digital: A1F
 
 
Turn hex 10 hex 2.16
    A1F hexadecimal number is converted to decimal calculation:
        10*16^2 + 1*16^1 + 15*16^0 = 2560 + 16 + 15 = 2591
 
3.excel column name computing (26 hex decimal turn, thought the same 1)
    It should be noted, excel column names computing, transforming an ordinary band is not the same, starting from 1, nor into the full 26 1, 26 is still a full 26 (Z), 27 then becomes AA (starting at 1)
    Code:
     
public String convertToTitle(int n) {
        StringBuilder strBuilder = new StringBuilder();
        while(n != 0){
            n--;
            int x = n % 26;
            strBuilder.insert(0,(char)('A' + x));
            n = n / 26;
        }
        return strBuilder.toString();
}

 

 

 

Guess you like

Origin www.cnblogs.com/wangzepu/p/12055390.html
Recommended