List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:org.jcurl.core.base.SlideCurves.java
/** * Add a discontinuity to the model.//w w w.jav a 2s . com * * @param t0 * [msec] * @param pos * @param speed * @param discontinuous * bitmask of the discontuous rocks */ @Override public void set(final double t0, final PositionSet pos, final SpeedSet speed, final int discontinuous) { if (log.isDebugEnabled()) log.debug("t0=" + t0 + " rockmask=" + Integer.toBinaryString(discontinuous)); if (t0 <= tmax) throw new IllegalArgumentException("t must grow!"); if (tmin == T0) tmin = t0; tmax = t0; for (int i = RockSet.ROCKS_PER_SET - 1; i >= 0; i--) if (0 != (discontinuous & 1 << i)) { if (log.isDebugEnabled()) log.debug("compute rock #" + i); // add a new curve to the list final R1RNFunction cu = createCurve(t0, pos.getRock(i), speed.getRock(i)); c[i].add(t0, new CurveInterval(t0, findThalt(t0, cu), cu)); } }
From source file:es.uniovi.imovil.fcrtrainer.HexadecimalExerciseFragment.java
public void updateUI() { if (tohex)// w w w. j a v a2 s . c o m tvNumberToConvert.setText(Integer.toBinaryString(numberToConvert)); else tvNumberToConvert.setText(Integer.toHexString(numberToConvert).toUpperCase(Locale.US)); }
From source file:jcurl.sim.core.SlideCurves.java
/** * Add a discontinuity to the model.//from w w w .j av a2 s . c o m * * @param t0 * [msec] * @param pos * @param speed * @param discontinuous * bitmask of the discontuous positions * @throws FunctionEvaluationException */ public void set(final double t0, final PositionSet pos, final SpeedSet speed, final int discontinuous) throws FunctionEvaluationException { if (log.isDebugEnabled()) log.debug("t0=" + t0 + " rockmask=" + Integer.toBinaryString(discontinuous)); if (t0 <= tmax) throw new IllegalArgumentException("t must grow!"); if (tmin == T0) tmin = t0; tmax = t0; for (int i = PositionSet.ROCKS_PER_SET - 1; i >= 0; i--) { if (0 != (discontinuous & (1 << i))) { log.info("compute rock #" + i); // add a new curve to the list final CurveGhost cu = createCurve(t0, pos.getRock(i), speed.getRock(i)); c[i].add(t0, new CurveInterval(t0, findThalt(t0, cu), cu)); } } }
From source file:com.telefonica.euro_iaas.paasmanager.claudia.impl.ClaudiaClientOpenStackImpl.java
public static String encode(String string) { if (string == null) { return ""; }/*from w w w . ja va 2 s.c o m*/ String whole_binary = ""; for (char c : string.toCharArray()) { String char_to_binary = Integer.toBinaryString(c); while (char_to_binary.length() < 8) char_to_binary = "0" + char_to_binary; whole_binary += char_to_binary; } string = ""; String suffix = ""; for (int i = 0; i < whole_binary.length(); i += 6) { String six_binary_digits = null; try { six_binary_digits = whole_binary.substring(i, i + 6); } catch (StringIndexOutOfBoundsException sioobe) { six_binary_digits = whole_binary.substring(i); while (six_binary_digits.length() < 6) { six_binary_digits += "00"; suffix += "="; } } string += radixBase64.charAt(Integer.parseInt(six_binary_digits, 2)); } return string + suffix; }
From source file:es.uniovi.imovil.fcrtrainer.TwosComplementExerciseFragment.java
private String toTwosComplement(String numb) { int num = Integer.parseInt(numb); char aux;//from w w w .jav a2s . c o m int tam; int res; String res_negativo = ""; String auxi = Integer.toBinaryString(Math.abs(num)); tam = auxi.length(); if (tam != NBIT) for (int i = 0; i < NBIT - tam; i++) auxi = "0" + auxi; if (num < 0) { for (int i = 0; i < NBIT; i++) { aux = (char) auxi.charAt(i); if (aux == '0') res_negativo = res_negativo + "1"; if (aux == '1') res_negativo = res_negativo + "0"; } res = (Integer.parseInt(res_negativo, 2)) + (Integer.parseInt("1", 2)); auxi = "" + Integer.toString(res, 2); } return auxi; }
From source file:es.uniovi.imovil.fcrtrainer.HexadecimalExerciseFragment.java
/** * Checks if the answer is correct. If the game mode is selected checks for * the number of questions that already has been asked, in case that number * is equal to the max number allowed calls endGame(). Also it adds a point * for each correct answer in that mode. * //from w w w .jav a2 s .c om * @param answer * the user input */ public void isCorrect(String answer) { etAnswer.setText(""); if (tohex) { if (answer.equals(Integer.toHexString(numberToConvert))) { showAnimationAnswer(true); if (game) updateGameState(); generateRandomNumber(); } else showAnimationAnswer(false); } else { if (answer.equals(Integer.toBinaryString(numberToConvert))) { showAnimationAnswer(true); if (game) updateGameState(); generateRandomNumber(); } else showAnimationAnswer(false); } }
From source file:aws.apps.usbDeviceEnumerator.ui.usbinfo.AndroidUsbInfoFragment.java
private String getEndpointText(final UsbEndpoint endpoint, final int index) { final String addressInBinary = CommonLogic.padLeft(Integer.toBinaryString(endpoint.getAddress()), "0", 8); String endpointText = "#" + index + "\n"; endpointText += getString(R.string.address_) + endpoint.getAddress() + " (" + addressInBinary + ")\n"; endpointText += getString(R.string.number_) + endpoint.getEndpointNumber() + "\n"; endpointText += getString(R.string.direction_) + UsbConstants.resolveUsbEndpointDirection(endpoint.getDirection()) + "\n"; endpointText += getString(R.string.type_) + UsbConstants.resolveUsbEndpointType(endpoint.getType()) + "\n"; endpointText += getString(R.string.poll_interval_) + endpoint.getInterval() + "\n"; endpointText += getString(R.string.max_packet_size_) + endpoint.getMaxPacketSize() + "\n"; endpointText += getString(R.string.attributes_) + CommonLogic.padLeft(Integer.toBinaryString(endpoint.getAttributes()), "0", 8); return endpointText; }
From source file:de.dfki.km.perspecting.obie.experiments.RelevanceRatingExperiment.java
public static void setUp(String $DATABASE_SERVER, String $DATABASE, TextCorpus corpus) throws Exception { pool.setUser($DATABASE_SERVER_USER); pool.setPassword($DATABASE_SERVER_PW); pool.setPortNumber($DATABASE_SERVER_PORT); pool.setDatabaseName($DATABASE);// www . j a v a 2s .c o m pool.setServerName($DATABASE_SERVER); pool.setMaxConnections(100); kb = new PostgresKB(pool.getConnection(), $DATABASE, new URI("http://test.de")); pipeline = new Pipeline(kb); LanguageIdentification languageClassification = new LanguageIdentification(Language.EN); WordSegmenter wordTokenizer = new WordSegmenter(); SentenceSegmenter sentenceTokenizer = new SentenceSegmenter(); POSModel posModel = new POSModel(Scoobie.class.getResourceAsStream("pos/en/en-pos-maxent.bin")); POSTagging posTagger = new POSTagging(new POSTaggerME(posModel)); ProperNameRecognition nounPhraseChunker = new ProperNameRecognition( new CRFNounPhraseChunkerModel($SCOOBIE_HOME + $DATABASE_DBPEDIA_en2 + "/npc/en/EN.crf")); SuffixArrayBuilder suffixArrayBuilder = new SuffixArrayBuilder(100, new LiteralHashing(4)); RDFLiteralSpotting namedEntityRecognizer = new RDFLiteralSpotting(); InstanceRecognition instanceResolver = new InstanceRecognition(); EntityDisambiguation instanceDisambiguator = new EntityDisambiguation( new AmbiguityResolver[] { new DegreeBasedResolver() }); KnownFactsRetrieval factRetrieval = new KnownFactsRetrieval(); ArrayList<int[]> l = new ArrayList<int[]>(); int max = (int) Math.pow(2, 9); for (int i = 0; i < max; i++) { String binary = Integer.toBinaryString(i); String prefix = ""; for (int pad = 0; pad < 9 - binary.length(); pad++) { prefix += "0"; } binary = prefix + binary; TIntHashSet s = new TIntHashSet(); for (int j = 0; j < 9; j++) { if (j < binary.length() && binary.charAt(j) == '1') { s.add(j); } } if (s.size() > 1) l.add(s.toArray()); } RelevanceRating relevanceRating = new RelevanceRating(new RatingMetric[] { new AuthorityBasedRating(), // 0 new HubBasedRating(), // 1 new PageRankBasedRating(), // 2 new DegreeBasedRating(), // 3 new CapacityBasedRating(), // 4 new RandomRating(), // 5 new PositionBasedRating(), // 6 new TermFrequencyBasedRating(), // 7 new InverseDocumentFrequencyBasedRating(corpus, new File(corpus.getCorpus().getAbsolutePath() + "/index/")) }, // 8 l.toArray(new int[l.size()][])); pipeline.configure(languageClassification, wordTokenizer, sentenceTokenizer, posTagger, nounPhraseChunker, suffixArrayBuilder, namedEntityRecognizer, new DummyTask(), new DummyTask(), instanceResolver, instanceDisambiguator, factRetrieval, relevanceRating, new DummyTask()); }
From source file:es.uniovi.imovil.fcrtrainer.HexadecimalExerciseFragment.java
public void showSolution() { if (tohex)/*w w w. java 2 s. c om*/ etAnswer.setText(Integer.toHexString(numberToConvert)); else etAnswer.setText(Integer.toBinaryString(numberToConvert)); }
From source file:voldemort.store.readonly.mr.HadoopStoreBuilderTest.java
@Test public void testHadoopBuild() throws Exception { // create test data Map<String, String> values = new HashMap<String, String>(); File testDir = TestUtils.createTempDir(); File tempDir = new File(testDir, "temp"), tempDir2 = new File(testDir, "temp2"); File outputDir = new File(testDir, "output"), outputDir2 = new File(testDir, "output2"); File storeDir = TestUtils.createTempDir(testDir); for (int i = 0; i < 200; i++) values.put(Integer.toString(i), Integer.toBinaryString(i)); // write test data to text file File inputFile = File.createTempFile("input", ".txt", testDir); inputFile.deleteOnExit();/*from w w w .j a va 2 s .c om*/ StringBuilder contents = new StringBuilder(); for (Map.Entry<String, String> entry : values.entrySet()) contents.append(entry.getKey() + "\t" + entry.getValue() + "\n"); FileUtils.writeStringToFile(inputFile, contents.toString()); String storeName = "test"; SerializerDefinition serDef = new SerializerDefinition("string"); Cluster cluster = ServerTestUtils.getLocalCluster(1); // Test backwards compatibility StoreDefinition def = new StoreDefinitionBuilder().setName(storeName) .setType(ReadOnlyStorageConfiguration.TYPE_NAME).setKeySerializer(serDef).setValueSerializer(serDef) .setRoutingPolicy(RoutingTier.CLIENT) .setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(1) .setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build(); HadoopStoreBuilder builder = new HadoopStoreBuilder(new Configuration(), TextStoreMapper.class, TextInputFormat.class, cluster, def, 64 * 1024, new Path(tempDir2.getAbsolutePath()), new Path(outputDir2.getAbsolutePath()), new Path(inputFile.getAbsolutePath()), CheckSumType.MD5, saveKeys, false); builder.build(); builder = new HadoopStoreBuilder(new Configuration(), TextStoreMapper.class, TextInputFormat.class, cluster, def, 64 * 1024, new Path(tempDir.getAbsolutePath()), new Path(outputDir.getAbsolutePath()), new Path(inputFile.getAbsolutePath()), CheckSumType.MD5, saveKeys, false); builder.build(); // Check if checkSum is generated in outputDir File nodeFile = new File(outputDir, "node-0"); // Check if metadata file exists File metadataFile = new File(nodeFile, ".metadata"); Assert.assertTrue(metadataFile.exists()); ReadOnlyStorageMetadata metadata = new ReadOnlyStorageMetadata(metadataFile); if (saveKeys) Assert.assertEquals(metadata.get(ReadOnlyStorageMetadata.FORMAT), ReadOnlyStorageFormat.READONLY_V2.getCode()); else Assert.assertEquals(metadata.get(ReadOnlyStorageMetadata.FORMAT), ReadOnlyStorageFormat.READONLY_V1.getCode()); Assert.assertEquals(metadata.get(ReadOnlyStorageMetadata.CHECKSUM_TYPE), CheckSum.toString(CheckSumType.MD5)); // Check contents of checkSum file byte[] md5 = Hex.decodeHex(((String) metadata.get(ReadOnlyStorageMetadata.CHECKSUM)).toCharArray()); byte[] checkSumBytes = CheckSumTests.calculateCheckSum(nodeFile.listFiles(), CheckSumType.MD5); Assert.assertEquals(0, ByteUtils.compare(checkSumBytes, md5)); // check if fetching works HdfsFetcher fetcher = new HdfsFetcher(); // Fetch to version directory File versionDir = new File(storeDir, "version-0"); fetcher.fetch(nodeFile.getAbsolutePath(), versionDir.getAbsolutePath()); Assert.assertTrue(versionDir.exists()); // open store @SuppressWarnings("unchecked") Serializer<Object> serializer = (Serializer<Object>) new DefaultSerializerFactory().getSerializer(serDef); ReadOnlyStorageEngine engine = new ReadOnlyStorageEngine(storeName, searchStrategy, new RoutingStrategyFactory().updateRoutingStrategy(def, cluster), 0, storeDir, 1); Store<Object, Object, Object> store = SerializingStore.wrap(engine, serializer, serializer, serializer); // check values for (Map.Entry<String, String> entry : values.entrySet()) { List<Versioned<Object>> found = store.get(entry.getKey(), null); Assert.assertEquals("Incorrect number of results", 1, found.size()); Assert.assertEquals(entry.getValue(), found.get(0).getValue()); } // also check the iterator - first key iterator... try { ClosableIterator<ByteArray> keyIterator = engine.keys(); if (!saveKeys) { fail("Should have thrown an exception since this RO format does not support iterators"); } int numElements = 0; while (keyIterator.hasNext()) { Assert.assertTrue(values.containsKey(serializer.toObject(keyIterator.next().get()))); numElements++; } Assert.assertEquals(numElements, values.size()); } catch (UnsupportedOperationException e) { if (saveKeys) { fail("Should not have thrown an exception since this RO format does support iterators"); } } // ... and entry iterator try { ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> entryIterator = engine.entries(); if (!saveKeys) { fail("Should have thrown an exception since this RO format does not support iterators"); } int numElements = 0; while (entryIterator.hasNext()) { Pair<ByteArray, Versioned<byte[]>> entry = entryIterator.next(); Assert.assertEquals(values.get(serializer.toObject(entry.getFirst().get())), serializer.toObject(entry.getSecond().getValue())); numElements++; } Assert.assertEquals(numElements, values.size()); } catch (UnsupportedOperationException e) { if (saveKeys) { fail("Should not have thrown an exception since this RO format does support iterators"); } } }