List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:edu.harvard.iq.dvn.ingest.dsb.SubsettableFileChecker.java
/** * test this byte buffer against R data file * *///from www.jav a2 s . c o m public String testRDAformat(MappedByteBuffer buff) { String result = null; buff.rewind(); boolean DEBUG = false; if (DEBUG) { out.println("applying the RData test\n"); out.println("buffer capacity=" + buff.capacity()); } if (DEBUG) { byte[] rawhdr = new byte[4]; buff.get(rawhdr, 0, 4); for (int j = 0; j < 4; j++) { out.printf("%02X ", rawhdr[j]); } out.println(); buff.rewind(); } // get the first 4 bytes as an int and check its value; // if it is 0x1F8B0800, then gunzip and its first 4 bytes int magicNumber = buff.getInt(); if (DEBUG) { out.println("magicNumber in decimal =" + magicNumber); out.println("in binary=" + Integer.toBinaryString(magicNumber)); out.println("in oct=" + Integer.toOctalString(magicNumber)); out.println("in hex=" + Integer.toHexString(magicNumber)); } try { if (magicNumber == 0x1F8B0800) { if (DEBUG) { out.println("magicNumber is GZIP"); } // gunzip the first 5 bytes and check their bye-pattern // get gzip buffer size int gzip_buffer_size = this.getGzipBufferSize(buff); byte[] hdr = new byte[gzip_buffer_size]; buff.get(hdr, 0, gzip_buffer_size); GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(hdr)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < RDA_HEADER_SIZE; i++) { sb.append(String.format("%02X", gzin.read())); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of compressed case } else { // uncompressed case? if (DEBUG) { out.println("magicNumber is not GZIP:" + magicNumber); out.println("test as an uncompressed RData file"); } buff.rewind(); byte[] uchdr = new byte[5]; buff.get(uchdr, 0, 5); StringBuilder sb = new StringBuilder(); for (int i = 0; i < uchdr.length; i++) { sb.append(String.format("%02X", uchdr[i])); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of uncompressed case } } catch (IOException ex) { ex.printStackTrace(); } return result; }
From source file:eap.util.EDcodeUtil.java
public static byte[] gbk2utf8(String chenese) { char c[] = chenese.toCharArray(); byte[] fullByte = new byte[3 * c.length]; for (int i = 0; i < c.length; i++) { int m = (int) c[i]; String word = Integer.toBinaryString(m); StringBuffer sb = new StringBuffer(); int len = 16 - word.length(); for (int j = 0; j < len; j++) { sb.append("0"); }/*from w ww. j av a 2 s. c om*/ sb.append(word); sb.insert(0, "1110"); sb.insert(8, "10"); sb.insert(16, "10"); byte[] bf = new byte[3]; bf[0] = Integer.valueOf(sb.substring(0, 8), 2).byteValue(); fullByte[i * 3] = bf[0]; bf[1] = Integer.valueOf(sb.substring(8, 16), 2).byteValue(); fullByte[i * 3 + 1] = bf[1]; bf[2] = Integer.valueOf(sb.substring(16), 2).byteValue(); fullByte[i * 3 + 2] = bf[2]; } return fullByte; }
From source file:com.downrighttech.dmxdip.MainActivity.java
private String swapBin(int input, int length) { String bin = Integer.toBinaryString(input); int pad = length - bin.length(); StringBuilder output = new StringBuilder(length); output.append(bin).reverse();//from w ww. jav a2s . c o m for (int i = 0; i < pad; i++) output.append("0"); return output.toString(); }
From source file:net.solarnetwork.node.control.sma.pcm.ModbusPCMController.java
@Override public List<SettingSpecifier> getSettingSpecifiers() { ModbusPCMController defaults = new ModbusPCMController(); List<SettingSpecifier> results = new ArrayList<SettingSpecifier>(20); // get current value BasicTitleSettingSpecifier status = new BasicTitleSettingSpecifier("status", "N/A", true); try {/*from w ww.j a v a 2s . c om*/ BitSet bits = currentDiscreetValue(); Integer val = integerValueForBitSet(bits); String binValue = Integer.toBinaryString(val); String padding = ""; if (binValue.length() < 4) { padding = String.format("%0" + (4 - binValue.length()) + "d", 0); } status.setDefaultValue( String.format("%s%s - %d%%", padding, binValue, percentValueForIntegerValue(val))); } catch (Exception e) { log.debug("Error reading PCM status: {}", e.getMessage()); } results.add(status); results.add(new BasicTextFieldSettingSpecifier("controlId", defaults.controlId)); results.add(new BasicTextFieldSettingSpecifier("groupUID", defaults.groupUID)); results.add(new BasicTextFieldSettingSpecifier("modbusNetwork.propertyFilters['UID']", "Serial Port")); results.add(new BasicTextFieldSettingSpecifier("unitId", String.valueOf(defaults.getUnitId()))); results.add(new BasicTextFieldSettingSpecifier("d1Address", defaults.d1Address.toString())); results.add(new BasicTextFieldSettingSpecifier("d2Address", defaults.d2Address.toString())); results.add(new BasicTextFieldSettingSpecifier("d3Address", defaults.d3Address.toString())); results.add(new BasicTextFieldSettingSpecifier("d4Address", defaults.d4Address.toString())); results.add(new BasicTextFieldSettingSpecifier("sampleCacheSeconds", String.valueOf(defaults.getSampleCacheSeconds()))); return results; }
From source file:pl.dp.bz.poid.fouriertest.FourierProc.java
private Complex[] computeInverseDIFForOneDimension(Complex[] pixelTable) { int bits = 9; double N = pixelTable.length; Complex[] transformedSignal = new Complex[(int) N]; for (int i = 0; i < transformedSignal.length; i++) { transformedSignal[i] = new Complex(0.0, 0.0); }/* w w w . ja va2s . c om*/ Complex signalTab[] = new Complex[(int) N]; Complex[] localTR = new Complex[(int) N]; int index = 0; for (int i = 0; i < pixelTable.length; i++) { signalTab[index] = new Complex(pixelTable[i].getReal(), pixelTable[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:edu.harvard.iq.dataverse.ingest.IngestableDataChecker.java
/** * test this byte buffer against R data file * *//* ww w . j a v a2s.com*/ public String testRDAformat(MappedByteBuffer buff) { String result = null; buff.rewind(); if (buff.capacity() < 4) { return null; } boolean DEBUG = false; if (DEBUG) { out.println("applying the RData test\n"); out.println("buffer capacity=" + buff.capacity()); } if (DEBUG) { byte[] rawhdr = new byte[4]; buff.get(rawhdr, 0, 4); for (int j = 0; j < 4; j++) { out.printf("%02X ", rawhdr[j]); } out.println(); buff.rewind(); } // get the first 4 bytes as an int and check its value; // if it is 0x1F8B0800, then gunzip and its first 4 bytes int magicNumber = buff.getInt(); if (DEBUG) { out.println("magicNumber in decimal =" + magicNumber); out.println("in binary=" + Integer.toBinaryString(magicNumber)); out.println("in oct=" + Integer.toOctalString(magicNumber)); out.println("in hex=" + Integer.toHexString(magicNumber)); } try { if (magicNumber == 0x1F8B0800) { if (DEBUG) { out.println("magicNumber is GZIP"); } // gunzip the first 5 bytes and check their bye-pattern // get gzip buffer size int gzip_buffer_size = this.getGzipBufferSize(buff); byte[] hdr = new byte[gzip_buffer_size]; buff.get(hdr, 0, gzip_buffer_size); GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(hdr)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < RDA_HEADER_SIZE; i++) { sb.append(String.format("%02X", gzin.read())); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of compressed case } else { // uncompressed case? if (DEBUG) { out.println("magicNumber is not GZIP:" + magicNumber); out.println("test as an uncompressed RData file"); } buff.rewind(); byte[] uchdr = new byte[5]; buff.get(uchdr, 0, 5); StringBuilder sb = new StringBuilder(); for (int i = 0; i < uchdr.length; i++) { sb.append(String.format("%02X", uchdr[i])); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of uncompressed case } } catch (IOException ex) { ex.printStackTrace(); } return result; }
From source file:nrec.basil.wimuconsole.SensorSettingsActivity.java
private void displayInsData(byte[] ins) { TextView t;/* w w w.j av a 2s .c om*/ DecimalFormat form = new DecimalFormat("##0.00"); ByteBuffer insbuffer = ByteBuffer.wrap(ins); insbuffer.order(ByteOrder.LITTLE_ENDIAN); // Display INS data t = (TextView) findViewById(R.id.statusreport); String status = null; byte stat = insbuffer.get(22); if (D) Log.d(TAG, "INS Status: " + stat); switch (stat) { case 0: status = "Calibrating"; break; case 1: status = "Aligning"; break; case 2: status = "Navigating"; break; case 3: status = "Invalid Data"; break; case 4: status = "Stopped"; break; } t.setText(status); t = (TextView) findViewById(R.id.solutionreport); String solution = null; solution = String.format("%8s", Integer.toBinaryString(insbuffer.get(23) & 0xFF)).replace(' ', '0'); t.setText(solution); t = (TextView) findViewById(R.id.px); mCurrentLatitude = insbuffer.getDouble(25); t.setText(form.format(insbuffer.getDouble(25))); t = (TextView) findViewById(R.id.py); mCurrentLongitude = insbuffer.getDouble(33); t.setText(form.format(insbuffer.getDouble(33))); t = (TextView) findViewById(R.id.pz); t.setText(form.format(insbuffer.getDouble(41))); t = (TextView) findViewById(R.id.vx); t.setText(form.format(insbuffer.getDouble(49))); t = (TextView) findViewById(R.id.vy); t.setText(form.format(insbuffer.getDouble(57))); t = (TextView) findViewById(R.id.vz); t.setText(form.format(insbuffer.getDouble(65))); t = (TextView) findViewById(R.id.ox); t.setText(form.format(insbuffer.getDouble(73) * R2D)); t = (TextView) findViewById(R.id.oy); t.setText(form.format(insbuffer.getDouble(81) * R2D)); t = (TextView) findViewById(R.id.oz); t.setText(form.format(insbuffer.getDouble(89) * R2D)); }
From source file:org.glite.security.voms.admin.operations.VOMSPermission.java
public String toBinaryString() { return Integer.toBinaryString(bits); }
From source file:org.red5.io.m4a.impl.AACReader.java
/** * Process the audio information contained in the atoms. * * @param stbl// w w w. j a v a 2 s . c o m * @param ase AudioSampleEntry * @param scale timescale */ private void processAudioBox(SampleTableBox stbl, AudioSampleEntry ase, long scale) { // get codec String codecName = ase.getType(); // set the audio codec here - may be mp4a or... setAudioCodecId(codecName); log.debug("Sample size: {}", ase.getSampleSize()); long ats = ase.getSampleRate(); // skip invalid audio time scale if (ats > 0) { audioTimeScale = ats * 1.0; } log.debug("Sample rate (audio time scale): {}", audioTimeScale); audioChannels = ase.getChannelCount(); log.debug("Channels: {}", audioChannels); if (ase.getBoxes(ESDescriptorBox.class).size() > 0) { // look for esds ESDescriptorBox esds = ase.getBoxes(ESDescriptorBox.class).get(0); if (esds == null) { log.debug("esds not found in default path"); // check for decompression param atom AppleWaveBox wave = ase.getBoxes(AppleWaveBox.class).get(0); if (wave != null) { log.debug("wave atom found"); // wave/esds esds = wave.getBoxes(ESDescriptorBox.class).get(0); if (esds == null) { log.debug("esds not found in wave"); // mp4a/esds //AC3SpecificBox mp4a = wave.getBoxes(AC3SpecificBox.class).get(0); //esds = mp4a.getBoxes(ESDescriptorBox.class).get(0); } } } //mp4a: esds if (esds != null) { // http://stackoverflow.com/questions/3987850/mp4-atom-how-to-discriminate-the-audio-codec-is-it-aac-or-mp3 ESDescriptor descriptor = esds.getEsDescriptor(); if (descriptor != null) { DecoderConfigDescriptor configDescriptor = descriptor.getDecoderConfigDescriptor(); AudioSpecificConfig audioInfo = configDescriptor.getAudioSpecificInfo(); if (audioInfo != null) { audioDecoderBytes = audioInfo.getConfigBytes(); /* the first 5 (0-4) bits tell us about the coder used for aacaot/aottype * http://wiki.multimedia.cx/index.php?title=MPEG-4_Audio 0 - NULL 1 - AAC Main (a deprecated AAC profile from MPEG-2) 2 - AAC LC or backwards compatible HE-AAC 3 - AAC Scalable Sample Rate 4 - AAC LTP (a replacement for AAC Main, rarely used) 5 - HE-AAC explicitly signaled (Non-backward compatible) 23 - Low Delay AAC 29 - HE-AACv2 explicitly signaled 32 - MP3on4 Layer 1 33 - MP3on4 Layer 2 34 - MP3on4 Layer 3 */ byte audioCoderType = audioDecoderBytes[0]; //match first byte switch (audioCoderType) { case 0x02: log.debug("Audio type AAC LC"); case 0x11: //ER (Error Resilient) AAC LC log.debug("Audio type ER AAC LC"); default: audioCodecType = 1; //AAC LC break; case 0x01: log.debug("Audio type AAC Main"); audioCodecType = 0; //AAC Main break; case 0x03: log.debug("Audio type AAC SBR"); audioCodecType = 2; //AAC LC SBR break; case 0x05: case 0x1d: log.debug("Audio type AAC HE"); audioCodecType = 3; //AAC HE break; case 0x20: case 0x21: case 0x22: log.debug("Audio type MP3"); audioCodecType = 33; //MP3 audioCodecId = "mp3"; break; } log.debug("Audio coder type: {} {} id: {}", new Object[] { audioCoderType, Integer.toBinaryString(audioCoderType), audioCodecId }); } else { log.debug("Audio specific config was not found"); DecoderSpecificInfo info = configDescriptor.getDecoderSpecificInfo(); if (info != null) { log.debug("Decoder info found: {}", info.getTag()); // qcelp == 5 } } } else { log.debug("No ES descriptor found"); } } } else { log.debug("Audio sample entry had no descriptor"); } //stsc - has Records SampleToChunkBox stsc = stbl.getSampleToChunkBox(); // stsc if (stsc != null) { log.debug("Sample to chunk atom found"); audioSamplesToChunks = stsc.getEntries(); log.debug("Audio samples to chunks: {}", audioSamplesToChunks.size()); // handle instance where there are no actual records (bad f4v?) } //stsz - has Samples SampleSizeBox stsz = stbl.getSampleSizeBox(); // stsz if (stsz != null) { log.debug("Sample size atom found"); audioSamples = stsz.getSampleSizes(); log.debug("Samples: {}", audioSamples.length); // if sample size is 0 then the table must be checked due to variable sample sizes audioSampleSize = stsz.getSampleSize(); log.debug("Sample size: {}", audioSampleSize); long audioSampleCount = stsz.getSampleCount(); log.debug("Sample count: {}", audioSampleCount); } //stco - has Chunks ChunkOffsetBox stco = stbl.getChunkOffsetBox(); // stco / co64 if (stco != null) { log.debug("Chunk offset atom found"); audioChunkOffsets = stco.getChunkOffsets(); log.debug("Chunk count: {}", audioChunkOffsets.length); } else { //co64 - has Chunks ChunkOffset64BitBox co64 = stbl.getBoxes(ChunkOffset64BitBox.class).get(0); if (co64 != null) { log.debug("Chunk offset (64) atom found"); audioChunkOffsets = co64.getChunkOffsets(); log.debug("Chunk count: {}", audioChunkOffsets.length); } } //stts - has TimeSampleRecords TimeToSampleBox stts = stbl.getTimeToSampleBox(); // stts if (stts != null) { log.debug("Time to sample atom found"); List<TimeToSampleBox.Entry> records = stts.getEntries(); log.debug("Audio time to samples: {}", records.size()); // handle instance where there are no actual records (bad f4v?) if (records.size() > 0) { TimeToSampleBox.Entry rec = records.get(0); log.debug("Samples = {} delta = {}", rec.getCount(), rec.getDelta()); //if we have 1 record it means all samples have the same duration audioSampleDuration = rec.getDelta(); } } // sdtp - sample dependency type SampleDependencyTypeBox sdtp = stbl.getSampleDependencyTypeBox(); // sdtp if (sdtp != null) { log.debug("Independent and disposable samples atom found"); List<SampleDependencyTypeBox.Entry> recs = sdtp.getEntries(); for (SampleDependencyTypeBox.Entry rec : recs) { log.debug("{}", rec); } } }
From source file:marytts.util.string.StringUtils.java
public static boolean isDesired(int currentFeature, int desiredFeatures, int maxFeatureStringLen) { boolean bRet; String str1 = Integer.toBinaryString(desiredFeatures); String str2 = Integer.toBinaryString(currentFeature); if (maxFeatureStringLen < str1.length()) maxFeatureStringLen = str1.length(); if (maxFeatureStringLen < str2.length()) maxFeatureStringLen = str2.length(); while (str1.length() < maxFeatureStringLen) str1 = "0" + str1; while (str2.length() < maxFeatureStringLen) str2 = "0" + str2; bRet = false;/*from w ww .ja v a 2s . c o m*/ for (int i = 0; i < str1.length(); i++) { if (Integer.valueOf(String.valueOf(str1.charAt(i))) == 1 && Integer.valueOf(String.valueOf(str2.charAt(i))) == 1) { bRet = true; break; } } return bRet; }