List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:uk.org.funcube.fcdw.server.processor.DataProcessor.java
public 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 ww w . ja v a2 s. c o m*/ return sb.toString(); }
From source file:org.janusgraph.TestBed.java
public static String toBinary(int b) { String res = Integer.toBinaryString(b); while (res.length() < 32) res = "0" + res; return res;// ww w .j ava2 s . c om }
From source file:net.spfbl.core.Huffman.java
public String decode(byte[] byteArray, int deslocamento) { StringBuilder builder = new StringBuilder(); for (int i = deslocamento; i < byteArray.length; i++) { byte octet = byteArray[i]; int codeInt = octet & 0xFF; String code = Integer.toBinaryString(codeInt); while (code.length() < 8) { code = '0' + code; }//from w ww . j a v a 2 s. c om builder.append(code); } return decode(builder.toString()); }
From source file:org.latticesoft.util.common.ConvertUtil.java
public static String formatBinary(int value) { StringBuffer sb = new StringBuffer(); String s = Integer.toBinaryString(value); for (int i = s.length(); i < 32; i++) { sb.append("0"); }/*from w w w . jav a2 s. co m*/ sb.append(s); s = sb.toString(); sb.setLength(0); for (int i = 0; i < 32; i++) { sb.append(s.charAt(i)); if (i > 0 && (i + 1) % 4 == 0) { sb.append(" "); } } return sb.toString(); }
From source file:com.shadows.hkprogrammer.core.MessageHandler.java
private ParameterMessage CreateParameterMessageFromBytes(ByteArray msgBytes) { ByteArray Payload = msgBytes.Read(2, msgBytes.length - 4); ParameterMessage message = new ParameterMessage(); String BaseTypesValue = Integer.toBinaryString(Payload.Read(0, 1).ToByte()); String BaseTypes = StringUtils.leftPad(BaseTypesValue, 8, '0'); message.setTXModelType(TXModel.fromInteger(Integer.parseInt(BaseTypes.substring(0, 4), 2))); String CraftTypeString = BaseTypes.substring(4, 8); message.setCraftTypeNum(CraftType.fromInteger(Integer.parseInt(CraftTypeString, 2))); for (int i = 0; i < 3; i++) { int onValue = Payload.Read(2 + (i) * 2, 1).ToByte(), offValue = Payload.Read(3 + (i) * 2, 1).ToByte(); message.setDRValueForChannel(DRChannel.fromInteger(i), onValue, offValue); int swash = Payload.Read(8 + i, 1).ToByte(); message.setSwashValueForChannel(SwashChannel.fromInteger(i), swash); String mixCommunicationValue = Integer.toBinaryString(Payload.Read(49 + i * 4, 1).ToByte()); String mixCommunication = StringUtils.leftPad(mixCommunicationValue, 8, '0'); int mixUprate = Payload.Read(50 + i * 4, 1).ToByte(), mixDownrate = Payload.Read(51 + i * 4, 1).ToByte(), mixSwitch = Payload.Read(52 + i * 4, 1).ToByte(); message.setMixSettingsValue(i + 1, MixDestination.fromInteger(Integer.parseInt(mixCommunication.substring(4, 8), 2)), MixSource.fromInteger(Integer.parseInt(mixCommunication.substring(0, 4), 2)), MixSwitch.fromInteger(mixSwitch), mixDownrate, mixUprate); }/*from w w w.j a va 2 s . c o m*/ String ReverseBytes = Integer.toBinaryString(Payload.Read(1, 1).ToByte()); ReverseBytes = StringUtils.leftPad(ReverseBytes, 8, '0'); for (int i = 0; i < 6; i++) { int endPointLeft = Payload.Read(11 + (i) * 2, 1).ToByte(), endPointRight = Payload.Read(12 + (i) * 2, 1).ToByte(); message.setEndPointValueForChannel(ControlChannel.fromInteger(i), endPointLeft, endPointRight); message.setReverseBitmaskForChannel(ControlChannel.fromInteger(i), Integer.parseInt(ReverseBytes.substring(7 - i, 8 - i), 2) == 1); int subtrim = Payload.Read(43 + i, 1).ToByte(); message.setSubtrimValueForChannel(ControlChannel.fromInteger(i), subtrim); } for (int i = 0; i < 5; i++) { byte throttleNormal = Payload.Read(23 + (i) * 2, 1).ToByte(), throttleId = Payload.Read(24 + (i) * 2, 1).ToByte(), pitchNormal = Payload.Read(33 + (i) * 2, 1).ToByte(), pitchId = Payload.Read(34 + (i) * 2, 1).ToByte(); message.setThrottleCurveValueForChannel(HeliEndPoint.fromInteger(i), throttleNormal, throttleId); message.setPitchCurveValueForChannel(HeliEndPoint.fromInteger(i), pitchNormal, pitchId); } for (int i = 0; i < 2; i++) { int SwitchFunctionVal = Payload.Read(61 + i, 1).ToByte(), VRFunctionVal = Payload.Read(63 + i, 1).ToByte(); message.setSwitchFunction(SwitchType.fromInteger(i), SwitchFunction.fromInteger(SwitchFunctionVal)); message.setVRFunction(VRType.fromInteger(i), VRFunction.fromInteger(VRFunctionVal)); } return message; }
From source file:com.google.android.car.kitchensink.sensor.SensorsTestFragment.java
private void refreshUi() { String summaryString;//from w w w . jav a 2 s . co m synchronized (this) { List<String> summary = new ArrayList<>(); for (Integer i : supportedSensors) { CarSensorEvent event = mEventMap.get(i); switch (i) { case CarSensorManager.SENSOR_TYPE_COMPASS: summary.add(getCompassString(event)); break; case CarSensorManager.SENSOR_TYPE_CAR_SPEED: summary.add(getContext().getString(R.string.sensor_speed, getTimestamp(event), event == null ? mNaString : event.getCarSpeedData().carSpeed)); break; case CarSensorManager.SENSOR_TYPE_RPM: summary.add(getContext().getString(R.string.sensor_rpm, getTimestamp(event), event == null ? mNaString : event.getRpmData().rpm)); break; case CarSensorManager.SENSOR_TYPE_ODOMETER: summary.add(getContext().getString(R.string.sensor_odometer, getTimestamp(event), event == null ? mNaString : event.getOdometerData().kms)); break; case CarSensorManager.SENSOR_TYPE_FUEL_LEVEL: String level = mNaString; String range = mNaString; String lowFuelWarning = mNaString; if (event != null) { CarSensorEvent.FuelLevelData fuelData = event.getFuelLevelData(); level = fuelData.level == -1 ? level : String.valueOf(fuelData.level); range = fuelData.range == -1 ? range : String.valueOf(fuelData.range); lowFuelWarning = String.valueOf(fuelData.lowFuelWarning); } summary.add(getContext().getString(R.string.sensor_fuel_level, getTimestamp(event), level, range, lowFuelWarning)); break; case CarSensorManager.SENSOR_TYPE_PARKING_BRAKE: summary.add(getContext().getString(R.string.sensor_parking_brake, getTimestamp(event), event == null ? mNaString : event.getParkingBrakeData().isEngaged)); break; case CarSensorManager.SENSOR_TYPE_GEAR: summary.add(getContext().getString(R.string.sensor_gear, getTimestamp(event), event == null ? mNaString : event.getGearData().gear)); break; case CarSensorManager.SENSOR_TYPE_NIGHT: summary.add(getContext().getString(R.string.sensor_night, getTimestamp(event), event == null ? mNaString : event.getNightData().isNightMode)); break; case CarSensorManager.SENSOR_TYPE_LOCATION: summary.add(getLocationString(event)); break; case CarSensorManager.SENSOR_TYPE_DRIVING_STATUS: String drivingStatus = mNaString; String binDrivingStatus = mNaString; if (event != null) { CarSensorEvent.DrivingStatusData drivingStatusData = event.getDrivingStatusData(); drivingStatus = String.valueOf(drivingStatusData.status); binDrivingStatus = Integer.toBinaryString(drivingStatusData.status); } summary.add(getContext().getString(R.string.sensor_driving_status, getTimestamp(event), drivingStatus, binDrivingStatus)); break; case CarSensorManager.SENSOR_TYPE_ENVIRONMENT: String temperature = mNaString; String pressure = mNaString; if (event != null) { CarSensorEvent.EnvironmentData env = event.getEnvironmentData(); temperature = Float.isNaN(env.temperature) ? temperature : String.valueOf(env.temperature); pressure = Float.isNaN(env.pressure) ? pressure : String.valueOf(env.pressure); } summary.add(getContext().getString(R.string.sensor_environment, getTimestamp(event), temperature, pressure)); break; case CarSensorManager.SENSOR_TYPE_ACCELEROMETER: summary.add(getAccelerometerString(event)); break; case CarSensorManager.SENSOR_TYPE_GPS_SATELLITE: summary.add(getGpsSatelliteString(event)); break; case CarSensorManager.SENSOR_TYPE_GYROSCOPE: summary.add(getGyroscopeString(event)); break; case CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE: if (event != null) { CarSensorEvent.CarWheelTickDistanceData d = event.getCarWheelTickDistanceData(); summary.add(getContext().getString(R.string.sensor_wheel_ticks, getTimestamp(event), d.sensorResetCount, d.frontLeftWheelDistanceMm, d.frontRightWheelDistanceMm, d.rearLeftWheelDistanceMm, d.rearRightWheelDistanceMm)); } else { summary.add(getContext().getString(R.string.sensor_wheel_ticks, getTimestamp(event), mNaString, mNaString, mNaString, mNaString, mNaString)); } // Get the config data try { CarSensorConfig c = mSensorManager .getSensorConfig(CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); summary.add(getContext().getString(R.string.sensor_wheel_ticks_cfg, c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS), c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK), c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK), c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK), c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK))); } catch (CarNotConnectedException e) { Log.e(TAG, "Car not connected or not supported", e); } break; case CarSensorManager.SENSOR_TYPE_ABS_ACTIVE: summary.add(getContext().getString(R.string.sensor_abs_is_active, getTimestamp(event), event == null ? mNaString : event.getCarAbsActiveData().absIsActive)); break; case CarSensorManager.SENSOR_TYPE_TRACTION_CONTROL_ACTIVE: summary.add(getContext().getString(R.string.sensor_traction_control_is_active, getTimestamp(event), event == null ? mNaString : event.getCarTractionControlActiveData().tractionControlIsActive)); break; default: // Should never happen. Log.w(TAG, "Unrecognized event type: " + i); } } summaryString = TextUtils.join("\n", summary); } mHandler.post(new Runnable() { @Override public void run() { mSensorInfo.setText(summaryString); } }); }
From source file:org.bigtextml.topics.ParallelTopicModel.java
public ParallelTopicModel(BigLabelAlphabet topicAlphabet, double alphaSum, double beta) { //this.id=System.currentTimeMillis(); //this.data = new ArrayList<TopicAssignment>(); //this.data = CacheManagementServices.cacheManager.getCache("topicass"); this.data = (TopicAssignmentBigMap) ManagementServices.getBigMap("TopicAssignment"); this.topicAlphabet = topicAlphabet; this.numTopics = topicAlphabet.size(); if (Integer.bitCount(numTopics) == 1) { // exact power of 2 topicMask = numTopics - 1;/*from w ww .j ava2 s .c o m*/ topicBits = Integer.bitCount(topicMask); } else { // otherwise add an extra bit topicMask = Integer.highestOneBit(numTopics) * 2 - 1; topicBits = Integer.bitCount(topicMask); } this.alphaSum = alphaSum; this.alpha = new double[numTopics]; Arrays.fill(alpha, alphaSum / numTopics); this.beta = beta; tokensPerTopic = new int[numTopics]; formatter = NumberFormat.getInstance(); formatter.setMaximumFractionDigits(5); logger.info("Coded LDA: " + numTopics + " topics, " + topicBits + " topic bits, " + Integer.toBinaryString(topicMask) + " topic mask"); }
From source file:fr.enseirb.odroidx.remote_client.MainActivity.java
public String getLocalIpAddress() { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); String ipBinary = null;/*www . j a v a 2 s. co m*/ try { ipBinary = Integer.toBinaryString(wm.getConnectionInfo().getIpAddress()); } catch (Exception e) { } if (ipBinary != null) { while (ipBinary.length() < 32) { ipBinary = "0" + ipBinary; } String a = ipBinary.substring(0, 8); String b = ipBinary.substring(8, 16); String c = ipBinary.substring(16, 24); String d = ipBinary.substring(24, 32); String actualIpAddress = Integer.parseInt(d, 2) + "." + Integer.parseInt(c, 2) + "." + Integer.parseInt(b, 2) + "." + Integer.parseInt(a, 2); return actualIpAddress; } else { return null; } }
From source file:net.minecraftforge.fml.common.asm.transformers.AccessTransformer.java
private String toBinary(int num) { return String.format("%16s", Integer.toBinaryString(num)).replace(' ', '0'); }
From source file:d88.core.object.D88SObject.java
private byte[] onCreateObjectInfo() { String objTypeString = String.format("%2s", Integer.toBinaryString(this.objType.getValue())).replace(' ', '0'); String objFormString = String.format("%2s", Integer.toBinaryString(this.objForm.getValue())).replace(' ', '0'); String objAppIDString = String.format("%12s", Integer.toBinaryString(this.objAppID)).replace(' ', '0'); String objVerString = String.format("%8s", Integer.toBinaryString(this.objVer)).replace(' ', '0'); String info = objVerString + objAppIDString + objFormString + objTypeString; return new BigInteger(info, 2).toByteArray(); }