【小朽开源路-①初出茅庐】十进制转(2到16)进制原理及安卓实现
2014-03-15 21:40
295 查看
前言
我的开源路声明:[传送门]为了实现自己的目标,不幸自己就选择在博客园上练习自己英语。希望英语多,中文少,然后渐渐地成为习惯。加油!
Subject
实现十进制转(2到16)进制原理及安卓The Principle (原理)
①the Stack ADT (栈知识)
小朽是活学活用,栈知识复习[传送门]②the Short division (短除法)
Start...
the jar struckture
ALStack.java
package sedion.jeffli.action; import java.util.ArrayList;import java.util.Stack; /** * My Open-Source road * @author Jeff Li * * @param <T> */ public class ALStack<T> extends Stack<T> { /** * */ private static final long serialVersionUID = -1261738006146239371L; private ArrayList<T> stackList = null; //create an empty stack by creating an empty ArrayList public ALStack(){ stackList = new ArrayList<T>(); } }
BaseStr.java
package sedion.jeffli.action; import java.util.Scanner; public class BaseStr { public static void main(String[] args) { int num , b; Scanner keyIn = new Scanner(System.in); System.out.print("Enter a decimal number: "); num = keyIn.nextInt(); System.out.print("Enter a base (2 to 16): "); b = keyIn.nextInt(); System.out.print(" "+num+" base "+b+" is "+baseString(num, b)); } //the short division principle public static String baseString(int num,int b){ //digitChar.charAt(digit) is the character that represents the digit , 0 <= digit <= 15 String digitChar = "0123456789ABCDEF",numStr = ""; //stack holds the base-b digits of num ALStack<Character> stk = new ALStack<Character>(); do{ //push right-most digit on the stack stk.push(digitChar.charAt(num % b)); //remove right-most digit form num num /= b; }while(num != 0); while(!stk.isEmpty()){ //pop stack and add digit on top of stack to numStr numStr += stk.pop().charValue(); } return numStr; } }
*核心
短除法原理,短除就是在除法中写除数的地方写两个数共有的质因数,然后落下两个数被公有质因数整除的商,之后再除,以此类推,直到结果互质为止实现demo,its a bit easy ,right?
//push right-most digit on the stack stk.push(digitChar.charAt(num % b)); //remove right-most digit form num num /= b;
Andriod Practice
源码下载:链接:http://pan.baidu.com/share/link?shareid=1403222381&uk=3307409781 密码:ub64应用下载:链接:http://pan.baidu.com/share/link?shareid=1403222381&uk=3307409781 密码:ub64
勿喷,效果图
寄读者,寄知识来源
读者,你好!你我不相识,谢谢你们支持。我的梦想会越来越接近。keep on,共勉!知识来源 http://www.cnblogs.com/shitianzeng/articles/2336765.html
知识来源于想着,我走路想着玩一个。就玩好了,星期六快乐。
相关文章推荐
- 数据结构的应用——使用栈实现十进制到其他(2、8、16)进制的转换
- 数据结构的应用——使用栈实现十进制到其他(2、8、16)进制的转换
- NFramework开源AOP框架ORM的实现原理与应用
- NFramework开源AOP框架ORM的实现原理与应用
- 【iOS知识学习】_objective-c 十进制转换成16进制
- 把十进制整数转换为r(r=2)进制输出(顺序栈实现)
- FineUI(开源版)v6.0中FState服务器端验证的实现原理
- 利用栈实现把十进制整数转换为二至十六之间的任一进制数的功能
- 巧用一条SQL 实现其它进制到十进制转换
- CCITT CRC-16计算原理与实现【整理综合】
- 进制数转换器的VB算法实现(2/8/10/16进制数可以相互转换)
- 自定义函数 将十进制转化为16进制,将16换成 36的话,就可以转化为所有拼音字母的进制
- 同余幂的原理和C++实现,附赠一个10进制数转换为任意进制的数组的算法。
- [安卓] 16、ListView和GridView结合显示单元实现自定义列表显示效果
- RACLE中用一条SQL实现其它进制到十进制的转换
- 四字节16进制数转化成浮点数的原理是什么?
- 安卓自学笔记:16:通过Handler实现自动播放动画
- 16、Ping的实现原理,ping 命令格式。
- (转)NFramework开源AOP框架ORM的实现原理与应用
- Java Thread&Concurrency(16): 深入理解ArrayBlockingQueue及其实现原理