pswcell.java.svn-base

来自「java写的一个模拟cpu程序」· SVN-BASE 代码 · 共 115 行

SVN-BASE
115
字号
/**
 * PSWCell.java
 * 
 * 
 * @author 詹道楠
 * @date 2008-5-6
 */

package execute;

public class PSWCell extends Cell implements Parameters {
	
	private int state = 0;
	
	public static void main(String[] args) {

		PSWCell psw =  new PSWCell("0110");
		System.out.println(psw);
		psw.setState("1111111111111111111111101110");
		System.out.println(psw);

	}

	public PSWCell() {
		
		super(PSW);
		state = 0;
		
	}

	public PSWCell(String s) {
		
		super(PSW);
		state = (Integer.valueOf(s, 2));
		
	}

	public PSWCell(int state) {
		
		super(PSW);
		this.state = state;
		
	}

	/**
	 * Return the state.
	 */
	
	public int getState() {
	
		return state;
	
	}

	/**
	 * Return the state.
	 */
	
	public int getState(int i) {
	
		return state & i;
	
	}

	/**
	 * Clear the state.
	 */
	
	public void clearState(int i) {
	
		state = state & i;
		state = state & MASK;
	
	}

	/**
	 * Reset the state.
	 */
	
	public void setState(int i) {
	
		state = state | i;
		state = state & MASK;
	
	}

	/**
	 * Reset the state.
	 */
	
	public void setState(String s) {

		state = Integer.valueOf(s, 2) & MASK;
	
	}

	public String toString() {
		
		String stateString = Integer.toBinaryString(state);
		int i = 16 - stateString.length();
		
		if(i > 0) {
			StringBuffer sb = new StringBuffer(i);
			while(i > 0) {
				sb.append('0');
				--i;
			}
			return sb.toString() + stateString;
		}
		else
			return stateString;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?