List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:com.fjn.helper.common.util.StringUtil.java
/** * 10?2?8?16/* w ww .j a v a 2s .c om*/ * @param num * @return */ public static String dec2Bin_Oct_Hex(int num, int flag) { if (flag == 2) { return Integer.toBinaryString(num); } else if (flag == 8) { return Integer.toOctalString(num); } else if (flag == 16) { return Integer.toHexString(num); } else { return null; } }
From source file:AsciiTable.java
/** * Creates the window's contents (the table) * // w w w . j a v a 2 s.c o m * @param composite the parent composite */ private void createContents(Composite composite) { composite.setLayout(new FillLayout()); // The system font will not display the lower 32 // characters, so create one that will createFont(); // Create a table with visible headers // and lines, and set the font that we // created Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setLinesVisible(true); table.setRedraw(false); table.setFont(font); // Create the columns TableColumn[] columns = createColumns(table); for (int i = 0; i < MAX_CHARS; i++) { // Create a background color for this row colors[i] = new Color(table.getDisplay(), 255 - i, 127 + i, i); // Create the row in the table by creating // a TableItem and setting text for each // column int c = 0; TableItem item = new TableItem(table, SWT.NONE); item.setText(c++, String.valueOf((char) i)); item.setText(c++, String.valueOf(i)); item.setText(c++, Integer.toHexString(i).toUpperCase()); item.setText(c++, Integer.toOctalString(i)); item.setText(c++, Integer.toBinaryString(i)); item.setText(c++, i < CHAR_NAMES.length ? CHAR_NAMES[i] : ""); item.setBackground(colors[i]); } // Now that we've set the text into the columns, // we call pack() on each one to size it to the // contents. for (int i = 0, n = columns.length; i < n; i++) { columns[i].pack(); } // Set redraw back to true so that the table // will paint appropriately table.setRedraw(true); }
From source file:org.jcurl.core.impl.ColliderBase.java
/** * Iterate over all rocks and call/*from w w w .j a va 2s . co m*/ * {@link ColliderBase#computeWC(Rock, Rock, Rock, Rock, AffineTransform)} * for each pair. * <p> * Does not change <code>pos</code>! * </p> * <p> * Does not fire {@link RockSet#fireStateChanged()}! * </p> * * @see ColliderBase#computeWC(Rock, Rock, Rock, Rock, AffineTransform) * @param pos * @param speed * @param tr * <code>null</code> creates a new instance. * @return bitmask of the changed rocks */ public int compute(final RockSet<Pos> pos, final RockSet<Vel> speed, AffineTransform tr) { if (log.isDebugEnabled()) log.debug("compute()"); int hits = 0; if (tr == null) tr = new AffineTransform(); else tr.setToIdentity(); // TUNE Parallel for (int B = 0; B < RockSet.ROCKS_PER_SET; B++) for (int A = 0; A < B; A++) { if (log.isDebugEnabled()) log.debug("Compute hit " + A + "<->" + B); if (computeWC(pos.getRock(A), pos.getRock(B), speed.getRock(A), speed.getRock(B), tr)) { // mark the rocks' bits hit hits |= 1 << A; hits |= 1 << B; } } if (log.isDebugEnabled()) log.debug("hit rocks: " + Integer.toBinaryString(hits)); return hits; }
From source file:pl.dpbz.poid.zadanie4.utils.Fourier.java
public static Complex[] computeInverseFastFourier(Complex[] sound, int bits) { double N = sound.length; Complex[] transformedSignal = new Complex[(int) N]; for (int i = 0; i < transformedSignal.length; i++) { transformedSignal[i] = new Complex(0.0, 0.0); }/*from ww w.j a va 2 s . c om*/ Complex signalTab[] = new Complex[(int) N]; Complex[] localTR = new Complex[(int) N]; int index = 0; for (int i = 0; i < sound.length; i++) { signalTab[index] = new Complex(sound[i].getReal(), sound[i].getImaginary()); index++; } index = 0; for (Complex cv : signalTab) { // System.out.println("x(" + index + ") = " + cv.getReal() + " IM: i" + cv.getImaginary()); index++; } //Zmienna okrelajca na jakiej wielkoci ma operowa na tablicy int part = 2; //Ptla okrelajca cykl przechodzenia, przez kolejne kolumny for (int iteration = 1; iteration <= bits; iteration++) { // System.out.println("PART "+part); //Ile razy ma si wykona for (int i = 0; i < part; i += 2) { int r = 0; for (int actualIndex = (signalTab.length / part) * i, counter = 0; counter < signalTab.length / part; counter++, actualIndex++) { int secondIndex = (actualIndex + (signalTab.length / part)); Complex a = signalTab[actualIndex].add(signalTab[secondIndex]); Complex b = signalTab[actualIndex].subtract(signalTab[secondIndex]); Complex W = new Complex(Math.cos((2.0 * Math.PI * r) / N), Math.sin((2.0 * Math.PI * r) / N)); b = b.multiply(W); signalTab[actualIndex] = a; signalTab[secondIndex] = b; r += part - (part / 2); } } part += part; } localTR[0] = signalTab[0]; localTR[localTR.length - 1] = signalTab[signalTab.length - 1]; for (int i = 1; i < signalTab.length - 1; i++) { String bitIndex = Integer.toBinaryString(i); if (bitIndex.length() < bits) { while (bitIndex.length() < bits) { bitIndex = "0" + bitIndex; } } char[] tab = bitIndex.toCharArray(); for (int j = 0; j < tab.length / 2; j++) { char temp = tab[j]; tab[j] = tab[tab.length - j - 1]; tab[tab.length - j - 1] = temp; } bitIndex = new String(tab); localTR[Integer.parseInt(bitIndex, 2)] = signalTab[i]; } for (int i = 0; i < localTR.length; i++) { transformedSignal[i] = new Complex(localTR[i].getReal() / N, localTR[i].getImaginary() / N); } return transformedSignal; }
From source file:au.org.ala.delta.confor.ToDistTest.java
private String toBitString(int expectedBits) { String bitsString = Integer.toBinaryString(expectedBits); int length = bitsString.length(); if (length < 32) { for (int k = 0; k < 32 - length; k++) { bitsString = "0" + bitsString; }//from w w w .ja v a2 s. c o m } return bitsString; }
From source file:org.jcurl.core.base.Collider.java
/** * Iterate over all positions and call/*from w w w .j a v a2 s .c om*/ * {@link Collider#computeWC(Rock, Rock, Rock, Rock, AffineTransform)} for * each pair. * * @see Collider#computeWC(Rock, Rock, Rock, Rock, AffineTransform) * @param pos * @param speed * @return bitmask of the changed positions */ public int compute(PositionSet pos, SpeedSet speed) { if (log.isDebugEnabled()) log.debug("compute()"); int hits = 0; final AffineTransform mat = new AffineTransform(); for (int B = 0; B < RockSet.ROCKS_PER_SET; B++) { for (int A = 0; A < B; A++) { if (log.isDebugEnabled()) log.debug("Compute hit " + A + "<->" + B); if (computeWC(pos.getRock(A), pos.getRock(B), speed.getRock(A), speed.getRock(B), mat)) { // mark the positions' bits hit hits |= (1 << A); hits |= (1 << B); } } } if (log.isDebugEnabled()) log.debug("hit positions: " + Integer.toBinaryString(hits)); return hits; }
From source file:uk.org.funcube.fcdw.server.processor.WholeOrbitDataProcessorImpl.java
private static String convertHexBytePairToBinary(final String hexString) { final StringBuffer sb = new StringBuffer(); for (int i = 0; i < hexString.length(); i += 2) { final String hexByte = hexString.substring(i, i + 2); final int hexValue = Integer.parseInt(hexByte, 16); sb.append(StringUtils.leftPad(Integer.toBinaryString(hexValue), 8, "0")); }/*from www .ja v a 2 s . c o m*/ return sb.toString(); }
From source file:org.jcurl.core.base.CollissionStrategy.java
/** * Iterate over all rocks and call/*from ww w.ja v a2 s. c o m*/ * {@link CollissionStrategy#computeWC(Rock, Rock, Rock, Rock, AffineTransform)} * for each pair. * * @see CollissionStrategy#computeWC(Rock, Rock, Rock, Rock, * AffineTransform) * @param pos * @param speed * @return bitmask of the changed rocks */ public int compute(PositionSet pos, SpeedSet speed) { if (log.isDebugEnabled()) log.debug("compute()"); int hits = 0; final AffineTransform mat = new AffineTransform(); for (int B = 0; B < RockSet.ROCKS_PER_SET; B++) { for (int A = 0; A < B; A++) { if (log.isDebugEnabled()) log.debug("Compute hit " + A + "<->" + B); if (computeWC(pos.getRock(A), pos.getRock(B), speed.getRock(A), speed.getRock(B), mat)) { // mark the rocks' bits hit hits |= (1 << A); hits |= (1 << B); } } } if (log.isDebugEnabled()) log.debug("hit rocks: " + Integer.toBinaryString(hits)); return hits; }
From source file:org.jcurl.core.base.ColliderBase.java
/** * Iterate over all rocks and call//from w w w . ja va 2 s. c o m * {@link ColliderBase#computeWC(Rock, Rock, Rock, Rock, AffineTransform)} * for each pair. * <p> * Does not change <code>pos</code>! * </p> * <p> * Does not fire {@link SpeedSet#notifyChange()}! * </p> * * @see ColliderBase#computeWC(Rock, Rock, Rock, Rock, AffineTransform) * @param pos * @param speed * @param tr * <code>null</code> creates a new instance. * @return bitmask of the changed rocks */ public int compute(final PositionSet pos, final SpeedSet speed, AffineTransform tr) { if (log.isDebugEnabled()) log.debug("compute()"); int hits = 0; if (tr == null) tr = new AffineTransform(); else tr.setToIdentity(); for (int B = 0; B < RockSet.ROCKS_PER_SET; B++) for (int A = 0; A < B; A++) { if (log.isDebugEnabled()) log.debug("Compute hit " + A + "<->" + B); if (computeWC(pos.getRock(A), pos.getRock(B), speed.getRock(A), speed.getRock(B), tr)) { // mark the rocks' bits hit hits |= 1 << A; hits |= 1 << B; } } if (log.isDebugEnabled()) log.debug("hit rocks: " + Integer.toBinaryString(hits)); return hits; }
From source file:com.nikonhacker.emu.memory.AutoAllocatingMemory.java
/** * Perform a byte store/*from ww w .ja v a 2 s . c o m*/ * * @param value the value to store * @param addr the address of where to store */ public final void store8(int addr, int value) { if (logMemoryMessages) { System.err.println("Store8 address: 0x" + Integer.toHexString(addr) + " val: 0x" + Format.asHex((value & 0xFF), 2) + " - 0b" + StringUtils.leftPad(Integer.toBinaryString(value & 0xFF), 8).replace('0', ' ')); } byte[] pageData = writableMemory[getPTE(addr)]; if (pageData == null) { map(truncateToPage(addr), PAGE_SIZE, true, true, true); pageData = writableMemory[getPTE(addr)]; } pageData[getOffset(addr)] = (byte) value; }