List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:org.red5.io.m4a.impl.M4AReader.java
/** * Process the audio information contained in the atoms. * /* w w w . j a v a2s .c om*/ * @param stbl * @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:com.samsistemas.calendarview.widget.CalendarView.java
private void setTotalDayOfWeekend() { int[] weekendDay = new int[Integer.bitCount(mWeekend)]; char days[] = Integer.toBinaryString(mWeekend).toCharArray(); int day = 1;/*from ww w . j ava 2 s.c o m*/ int index = 0; for (int i = days.length - 1; i >= 0; i--) { if (days[i] == '1') { weekendDay[index] = day; index++; } day++; } mTotalDayOfWeekend = weekendDay; }
From source file:com.datatorrent.apps.logstream.DimensionOperator.java
/** * <b>Note:</b> This partitioner does not support parallel partitioning.<br/><br/> * {@inheritDoc}// w ww . j av a 2s . c o m */ @Override public Collection<Partition<DimensionOperator>> definePartitions( Collection<Partition<DimensionOperator>> partitions, PartitioningContext context) { ArrayList<Partition<DimensionOperator>> newPartitions = new ArrayList<Partition<DimensionOperator>>(); String[] filters = registry.list(LogstreamUtil.FILTER); int partitionSize; if (partitions.size() == 1) { // initial partitions; functional partitioning partitionSize = filters.length; } else { // redo partitions; double the partitions partitionSize = partitions.size() * 2; } for (int i = 0; i < partitionSize; i++) { try { DimensionOperator dimensionOperator = new DimensionOperator(); dimensionOperator.registry = registry; dimensionOperator.timeBucketFlags = timeBucketFlags; dimensionOperator.valueOperations = new HashMap<Integer, HashMap<String, HashSet<AggregateOperation>>>( valueOperations); dimensionOperator.dimensionCombinationList = new HashMap<Integer, ArrayList<Integer>>( dimensionCombinationList); Partition<DimensionOperator> partition = new DefaultPartition<DimensionOperator>(dimensionOperator); newPartitions.add(partition); } catch (Throwable ex) { DTThrowable.rethrow(ex); } } int partitionBits = (Integer.numberOfLeadingZeros(0) - Integer.numberOfLeadingZeros(partitionSize / filters.length - 1)); int partitionMask = 0; if (partitionBits > 0) { partitionMask = -1 >>> (Integer.numberOfLeadingZeros(-1)) - partitionBits; } partitionMask = (partitionMask << 16) | 0xffff; // right most 16 bits used for functional partitioning for (int i = 0; i < newPartitions.size(); i++) { Partition<DimensionOperator> partition = newPartitions.get(i); String partitionVal = filters[i % filters.length]; int bits = i / filters.length; int filterId = registry.getIndex(LogstreamUtil.FILTER, partitionVal); filterId = 0xffff & filterId; // clear out first 16 bits int partitionKey = (bits << 16) | filterId; // first 16 bits for dynamic partitioning, last 16 bits for functional partitioning logger.debug("partitionKey = {} partitionMask = {}", Integer.toBinaryString(partitionKey), Integer.toBinaryString(partitionMask)); partition.getPartitionKeys().put(in, new PartitionKeys(partitionMask, Sets.newHashSet(partitionKey))); } return newPartitions; }
From source file:com.android.tv.ui.TvOverlayManager.java
@UiThread private void onOverlayOpened(@TvOverlayType int overlayType) { if (DEBUG)/* w w w . ja va 2 s. com*/ Log.d(TAG, "Overlay opened: 0b" + Integer.toBinaryString(overlayType)); mOpenedOverlays |= overlayType; if (DEBUG) Log.d(TAG, "Opened overlays: 0b" + Integer.toBinaryString(mOpenedOverlays)); mHandler.removeMessages(MSG_OVERLAY_CLOSED); mMainActivity.updateKeyInputFocus(); }
From source file:com.android.tv.ui.TvOverlayManager.java
@UiThread private void onOverlayClosed(@TvOverlayType int overlayType) { if (DEBUG)/* w w w. j av a2 s . c o m*/ Log.d(TAG, "Overlay closed: 0b" + Integer.toBinaryString(overlayType)); mOpenedOverlays &= ~overlayType; if (DEBUG) Log.d(TAG, "Opened overlays: 0b" + Integer.toBinaryString(mOpenedOverlays)); mHandler.removeMessages(MSG_OVERLAY_CLOSED); mMainActivity.updateKeyInputFocus(); // Show the main menu again if there are no pop-ups or banners only. // The main menu should not be shown when the activity is in paused state. boolean menuAboutToShow = false; if (canExecuteCloseAction()) { menuAboutToShow = mMainActivity.getTimeShiftManager().isPaused(); mHandler.sendEmptyMessage(MSG_OVERLAY_CLOSED); } // Don't set screen name to main if the overlay closing is a banner // or if a non banner overlay is still open // or if we just opened the menu if (overlayType != OVERLAY_TYPE_SCENE_CHANNEL_BANNER && overlayType != OVERLAY_TYPE_SCENE_INPUT_BANNER && isOnlyBannerOrNoneOpened() && !menuAboutToShow) { mTracker.sendScreenView(MainActivity.SCREEN_NAME); } }
From source file:org.mathIT.gui.GraphViewer.java
/** * /*from ww w .j a v a 2 s . c o m*/ * @param args command line input (is ignored in this method) */ public static void main(String[] args) { //double inf = WeightedGraph.INFINITY; boolean binary = false; // whether vertex number should be shown in binary format boolean undirected = true; //int s; /* Haus-vom-Nikolaus example: --- undirected = false; double[][] w = { //1 2 3 4 5 { 0, 1, 1, 0, 0}, // 1 { 0, 0, 1, 1, 0}, // 2 { 0, 0, 0, 1, 0}, // 3 { 1, 0, 0, 0, 1}, // 4 { 0, 1, 0, 0, 0}, // 5 }; // */ /* Easley-Kleinberg example: --- undirected = true; double[][] w = { //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0 { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1 { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // 6 { 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, // 7 { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, // 8 { 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 9 { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0}, // 10 { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0}, // 11 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1}, // 12 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1}, // 13 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0}, // 14 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1}, // 15 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0}, // 16 }; // */ /* Permutation matrix: --- undirected = false; double[][] w = { //0 1 2 3 4 { 0, 0, 1, 0, 0}, // 0 { 0, 1, 0, 0, 0}, // 1 { 0, 0, 0, 0, 1}, // 2 { 1, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0}, // 4 }; // */ /* Permutation matrix 2: --- undirected = false; double[][] w = { //0 1 2 3 4 { 0, 1, 0, 0, 0}, // 0 { 0, 0, 1, 0, 0}, // 1 { 0, 0, 0, 1, 0}, // 2 { 0, 0, 0, 0, 1}, // 3 { 1, 0, 0, 0, 0}, // 4 }; // */ // /* Morone-Makse (2015), Fig. 1.A: --- undirected = true; double[][] w = { //0 1 2 3 4 5 { 0, 1, 0, 0, 0, 0 }, // 0 { 1, 0, 1, 0, 1, 0 }, // 1 { 0, 1, 0, 1, 1, 0 }, // 2 { 0, 0, 1, 0, 0, 0 }, // 3 { 0, 1, 1, 0, 0, 1 }, // 4 { 0, 0, 0, 0, 1, 0 }, // 5 }; // */ /* 3 cycles: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 9 10 11 12 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1 { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // 4 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // 6 { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // 8 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, // 9 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, // 10 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 11 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // 12 }; // */ /* shear mapping: --- undirected = false; double[][] w = { //1 2 { 1, 1}, // 1 { 0, 1}, // 2 }; // */ /* Adder gate: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 { 1, 0, 0, 0, 0, 0, 0, 0}, // 1 { 0, 1, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 0, 0, 1, 0}, // 5 { 0, 0, 0, 0, 0, 0, 0, 1}, // 6 { 0, 0, 0, 0, 0, 1, 0, 0}, // 7 { 0, 0, 0, 0, 1, 0, 0, 0}, // 8 }; binary = true; // */ /* 2-bit adder gate: --- undirected = false; double[][] w = { //1 2 3 4 { 1, 0, 0, 0}, // 1 { 0, 1, 0, 0}, // 2 { 0, 1, 0, 0}, // 3 { 0, 0, 1, 0}, // 4 }; binary = true; // */ /* Easley-Kleinberg toy web: --- undirected = false; double[][] w = { //1 2 3 4 { 0, 1, 0, 1}, // 1 { 0, 0, 1, 1}, // 2 { 1, 0, 0, 0}, // 3 { 0, 0, 1, 0}, // 4 }; // */ /* Easley-Kleinberg toy web variation: --- undirected = false; double[][] w = { //1 2 3 4 { 0, 1, 0, 1}, // 1 { 0, 0, 1, 1}, // 2 { 1, 0, 0, 0}, // 3 { 0, 0, 0, 0}, // 4 }; // */ /* Krumke-Noltemeier 3.4: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 { 0, 1, 0, 0, 0, 0, 0}, // 1 { 0, 0, 1, 1, 0, 0, 0}, // 2 { 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 0, 1, 0, 0}, // 4 { 0, 1, 0, 1, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 0, 0}, // 6 { 0, 0, 0, 0, 0, 1, 0}, // 7 }; // */ /* OR gate: --- double[][] w = { //1 2 3 4 5 6 7 8 { 0, 1, 0, 0, 0, 0, 0, 0}, // 1 { 1, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 1, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 0}, // 6 { 0, 0, 0, 0, 0, 0, 1, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 1}, // 8 }; binary = true; // */ /* cOR gate: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 { 0, 1, 0, 0, 0, 0, 0, 0}, // 1 { 0, 0, 0, 0, 0, 0, 1, 0}, // 2 { 0, 0, 0, 0, 1, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 1, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 0}, // 6 { 1, 0, 0, 0, 0, 0, 0, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 1}, // 8 }; binary = true; // */ /* Brandes et al 2008, Fig. 1a: --- double[][] w = { //1 2 3 4 5 6 { 0, 1, 1, 0, 0, 0}, // 1 { 1, 0, 1, 0, 1, 0}, // 2 { 1, 1, 0, 1, 0, 0}, // 3 { 0, 0, 1, 0, 0, 0}, // 4 { 0, 1, 0, 0, 0, 1}, // 5 { 0, 0, 0, 0, 1, 0}, // 6 }; // maximum modularity: C_0=[{0, 1, 2}, {3}, {4}, {5}], Q=0.013888888888888895 // */ Actor[] x = new Actor[w.length]; for (int i = 0; i < x.length; i++) { String name = ""; if (binary) { int jMax = Integer.numberOfLeadingZeros(i) - Integer.numberOfLeadingZeros(x.length) - 1; //System.out.println("i=" + i + ", jMax=" + jMax); for (int j = 0; j < jMax; j++) { name += "0"; } if (i != 0) name += Integer.toBinaryString(i); } else { //name += i; name += (i + 1); } //if (!binary && i < 10) name = " " + name; x[i] = new Actor(i, name, .5); } SocialNetwork graph = new SocialNetwork(undirected, x, w); //graph.activate(x[6], x[9]); visualize(graph); //new GraphViewer(graph); }
From source file:org.osgp.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
private String byteArrayToString(final byte[] bitStringValue) { if (bitStringValue == null || bitStringValue.length == 0) { return null; }/*from www. java 2s. c om*/ final StringBuilder sb = new StringBuilder(); for (final byte element : bitStringValue) { sb.append(StringUtils.leftPad(Integer.toBinaryString(element & 0xFF), 8, "0")); sb.append(" "); } return sb.toString(); }
From source file:org.nd4j.linalg.util.MathUtils.java
/** * This will translate a vector in to an equivalent integer * * @param vector the vector to translate * @return a z value such that the value is the interleaved lsd to msd for each * double in the vector/* w ww.j a v a 2 s . co m*/ */ public static int distanceFinderZValue(double[] vector) { StringBuilder binaryBuffer = new StringBuilder(); List<String> binaryReps = new ArrayList<String>(vector.length); for (int i = 0; i < vector.length; i++) { double d = vector[i]; int j = (int) d; String binary = Integer.toBinaryString(j); binaryReps.add(binary); } //append from left to right, the least to the most significant bit //till all strings are empty while (!binaryReps.isEmpty()) { for (int j = 0; j < binaryReps.size(); j++) { String curr = binaryReps.get(j); if (!curr.isEmpty()) { char first = curr.charAt(0); binaryBuffer.append(first); curr = curr.substring(1); binaryReps.set(j, curr); } else binaryReps.remove(j); } } return Integer.parseInt(binaryBuffer.toString(), 2); }
From source file:org.canova.api.util.MathUtils.java
/** * This will translate a vector in to an equivalent integer * * @param vector the vector to translate * @return a z value such that the value is the interleaved lsd to msd for each * double in the vector/*from w w w.j a v a2 s .c om*/ */ public static int distanceFinderZValue(double[] vector) { StringBuilder binaryBuffer = new StringBuilder(); List<String> binaryReps = new ArrayList<>(vector.length); for (double d : vector) { int j = (int) d; String binary = Integer.toBinaryString(j); binaryReps.add(binary); } //append from left to right, the least to the most significant bit //till all strings are empty while (!binaryReps.isEmpty()) { for (int j = 0; j < binaryReps.size(); j++) { String curr = binaryReps.get(j); if (!curr.isEmpty()) { char first = curr.charAt(0); binaryBuffer.append(first); curr = curr.substring(1); binaryReps.set(j, curr); } else binaryReps.remove(j); } } return Integer.parseInt(binaryBuffer.toString(), 2); }
From source file:org.deeplearning4j.clustering.util.MathUtils.java
/** * This will translate a vector in to an equivalent integer * @param vector the vector to translate * @return a z value such that the value is the interleaved lsd to msd for each * double in the vector//from w w w .j a va 2 s.c o m */ public static int distanceFinderZValue(double[] vector) { StringBuilder binaryBuffer = new StringBuilder(); List<String> binaryReps = new ArrayList<>(vector.length); for (int i = 0; i < vector.length; i++) { double d = vector[i]; int j = (int) d; String binary = Integer.toBinaryString(j); binaryReps.add(binary); } //append from left to right, the least to the most significant bit //till all strings are empty while (!binaryReps.isEmpty()) { for (int j = 0; j < binaryReps.size(); j++) { String curr = binaryReps.get(j); if (!curr.isEmpty()) { char first = curr.charAt(0); binaryBuffer.append(first); curr = curr.substring(1); binaryReps.set(j, curr); } else binaryReps.remove(j); } } return Integer.parseInt(binaryBuffer.toString(), 2); }