List of usage examples for java.lang Float floatToIntBits
@HotSpotIntrinsicCandidate public static int floatToIntBits(float value)
From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerMadUiInstance.java
public void sendPlayingSpeed(final float playingSpeed) { sendTemporalValueToInstance(SoundfilePlayerIOQueueBridge.COMMAND_IN_PLAY_SPEED, Float.floatToIntBits(playingSpeed)); }
From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerMadUiInstance.java
public void sendGain(final float gain) { sendTemporalValueToInstance(SoundfilePlayerIOQueueBridge.COMMAND_IN_GAIN, Float.floatToIntBits(gain)); }
From source file:ExposedFloat.java
void updateNumberFields() { int intBits = Float.floatToIntBits(value); if (Float.isNaN(value)) { base10Field.setText(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity base10Field.setText(negativeInfinityString); } else {//from w w w . j a va 2 s . c om // This is a positive infinity base10Field.setText(positiveInfinityString); } } else if (intBits == (int) 0x80000000) { base10Field.setText("-0"); } else { base10Field.setText(Float.toString(value)); } int v = intBits; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0: buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = intBits; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); if (intBits < 0) { signField.setText("1"); } else { signField.setText("0"); } v = intBits >> 23; buf.setLength(0); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } exponentField.setText(buf.toString()); // Do the mantissa v = intBits; buf.setLength(0); for (int i = 0; i < 23; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } if (((intBits >> 23) & 0xff) == 0) { // This is a denormalized number, first bit is 0 buf.insert(0, "0"); } else { // This is a normalized number, first bit is 1 buf.insert(0, "1"); } mantissaField.setText(buf.toString()); // Print out a denormalized base 2 version. buf.setLength(0); if (Float.isNaN(value)) { buf.append(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity buf.append(negativeInfinityString); } else { // This is a positive infinity buf.append(positiveInfinityString); } } else { if ((intBits >>> 31) == 1) { // This is a negative number buf.append("-"); } // Convert mantissa to int. v = (intBits & 0x007fffff); if (((intBits >> 23) & 0xff) != 0) { // Set bit 23 if the number is normalized v |= 0x00800000; } buf.append(v); // print out the exponent v = (intBits >> 23) & 0xff; if (v != 150 && intBits != 0 && intBits != (int) 0x80000000) { if (v != 0) { // regular normalized number buf.append("e" + (v - 150)); } else { // denormalized number buf.append("e-149"); } } } base2Field.setText(buf.toString()); }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Writes a signed float (four byte) value to the buffer, with support for * correct default sorting of all values. Writes values that can be read * using {@link TupleInput#readSortedFloat}. * /*from www . j a v a2 s .c om*/ * <p> * <code>Float.floatToIntBits</code> and the following bit manipulations are * used to convert the signed float value to a representation that is sorted * correctly by default. * </p> * * <pre> * int intVal = Float.floatToIntBits(val); * intVal ˆ= (intVal < 0) ? 0xffffffff : 0x80000000; * </pre> * * Based on com.sleepycat.bind.tuple (berkley db/ oracle) * * @param val * is the value to write to the buffer. * * @return this tuple output object. */ private static final String encodeSortedFloat(float val) { int intVal = Float.floatToIntBits(val); intVal ^= (intVal < 0) ? 0xffffffff : 0x80000000; intVal = (int) (intVal ^ 0x80000000); return encodeInt(intVal); }
From source file:com.bizosys.hsearch.index.DocMeta.java
/** * Returns all the necessary fields for processing. * orgUnit is treated specially. It goes in a column * This helps to search just on orgUnit fields and then * retrieve documents./*from w w w .ja v a 2 s . c om*/ * * It stores type.. If the type is * means matches all * */ public byte[] toBytes() { byte docTypeLen = (byte) 0; byte[] docTypeB = null; if (null != this.docType) { docTypeB = Storable.putString(this.docType); docTypeLen = (byte) docTypeB.length; } byte stateLen = (byte) 0; byte[] stateB = null; if (null != this.state) { stateB = Storable.putString(this.state); stateLen = (byte) stateB.length; } byte orgUnitLen = (byte) 0; byte[] orgUnitB = null; if (null != this.team) { orgUnitB = Storable.putString(this.team); orgUnitLen = (byte) orgUnitB.length; } byte geoHouseLen = (byte) 0; byte[] geoHouseB = null; if (null != this.geoHouse) { geoHouseB = Storable.putString(this.geoHouse); geoHouseLen = (byte) geoHouseB.length; } boolean isNorthing = false; byte[] northingB = null; if (this.northing != 0.0f) { isNorthing = true; northingB = Storable.putInt(Float.floatToIntBits(this.northing)); } boolean isEastering = false; byte[] easteringB = null; if (this.eastering != 0.0f) { isEastering = true; easteringB = Storable.putInt(Float.floatToIntBits(this.eastering)); } boolean isWeight = false; byte[] weightB = null; if (this.weight != 0) { isWeight = true; weightB = Storable.putInt(this.weight); } boolean isIpHouse = false; byte[] iphouseB = null; if (this.ipHouse != 0) { isIpHouse = true; iphouseB = Storable.putInt(this.ipHouse); } boolean isTags = false; byte[] tagsB = null; if (null != this.tags) { isTags = true; tagsB = Storable.putString(this.tags); } boolean isSocialText = false; byte[] socialTextB = null; if (null != this.socialText) { isSocialText = true; this.socialText = this.socialText.toLowerCase(); socialTextB = Storable.putString(this.socialText); } boolean isBornOn = false; byte[] bornOnB = null; if (null != this.createdOn) { isBornOn = true; bornOnB = Storable.putLong(this.createdOn.getTime()); } boolean isModifiedOn = false; byte[] modifiedOnB = null; if (null != this.modifiedOn) { isModifiedOn = true; modifiedOnB = Storable.putLong(this.modifiedOn.getTime()); } boolean isDeathOn = false; byte[] deathOnB = null; if (null != this.validTill) { isDeathOn = true; deathOnB = Storable.putLong(this.validTill.getTime()); } byte flag_1 = Storable.bitsToByte(new boolean[] { isEastering, isNorthing, isWeight, isIpHouse, securityHigh, sentimentPositive, isTags, isSocialText }); byte flag_2 = Storable .bitsToByte(new boolean[] { isBornOn, isModifiedOn, isDeathOn, false, false, false, false, false }); int totalBytes = 1 /** docTypeLen */ + 1 /** stateLen */ + 1 /** orgUnitLen */ + 1 /** geoHouseLen */ + 1 /** dataPresence */ + 1 /** timePresence */ + docTypeLen + stateLen + orgUnitLen + geoHouseLen; if (isEastering) totalBytes = totalBytes + 4; if (isNorthing) totalBytes = totalBytes + 4; if (isWeight) totalBytes = totalBytes + 4; if (isIpHouse) totalBytes = totalBytes + 4; if (isTags) totalBytes = totalBytes + tagsB.length + 2; if (isSocialText) totalBytes = totalBytes + socialTextB.length + 2; if (isBornOn) totalBytes = totalBytes + 8; if (isModifiedOn) totalBytes = totalBytes + 8; if (isDeathOn) totalBytes = totalBytes + 8; /** * Writing Start */ byte[] bytes = new byte[totalBytes]; int pos = 0; bytes[pos++] = docTypeLen; if (0 != docTypeLen) System.arraycopy(docTypeB, 0, bytes, pos, docTypeLen); pos = pos + docTypeLen; bytes[pos++] = stateLen; if (0 != stateLen) System.arraycopy(stateB, 0, bytes, pos, stateLen); pos = pos + stateLen; bytes[pos++] = orgUnitLen; if (0 != orgUnitLen) System.arraycopy(orgUnitB, 0, bytes, pos, orgUnitLen); pos = pos + orgUnitLen; bytes[pos++] = geoHouseLen; if (0 != geoHouseLen) System.arraycopy(geoHouseB, 0, bytes, pos, geoHouseLen); pos = pos + geoHouseLen; bytes[pos] = flag_1; pos++; bytes[pos] = flag_2; pos++; if (isEastering) { System.arraycopy(easteringB, 0, bytes, pos, 4); pos = pos + 4; } if (isNorthing) { System.arraycopy(northingB, 0, bytes, pos, 4); pos = pos + 4; } if (isWeight) { System.arraycopy(weightB, 0, bytes, pos, 4); pos = pos + 4; } if (isIpHouse) { System.arraycopy(iphouseB, 0, bytes, pos, 4); pos = pos + 4; } if (isTags) { System.arraycopy(Storable.putShort((short) tagsB.length), 0, bytes, pos, 2); pos = pos + 2; System.arraycopy(tagsB, 0, bytes, pos, tagsB.length); pos = pos + tagsB.length; } if (isSocialText) { System.arraycopy(Storable.putShort((short) socialTextB.length), 0, bytes, pos, 2); pos = pos + 2; System.arraycopy(socialTextB, 0, bytes, pos, socialTextB.length); pos = pos + socialTextB.length; } if (isBornOn) { System.arraycopy(bornOnB, 0, bytes, pos, 8); pos = pos + 8; } if (isModifiedOn) { System.arraycopy(modifiedOnB, 0, bytes, pos, 8); pos = pos + 8; } if (isDeathOn) { System.arraycopy(deathOnB, 0, bytes, pos, 8); pos = pos + 8; } return bytes; }
From source file:org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinarySerializeWrite.java
@Override public void writeFloat(float vf) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0;/*from w w w .jav a2s . co m*/ nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); int v = Float.floatToIntBits(vf); output.write((byte) (v >> 24)); output.write((byte) (v >> 16)); output.write((byte) (v >> 8)); output.write((byte) (v)); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
From source file:JVMSimulator.java
void ExecuteNextInstruction() { int a, b, result, i, operand0, operand1, operand2, offset; float fa, fb, fresult; Float f;/* w ww.ja v a2 s . c o m*/ int nextOpCode = methodAreaMemorySection.getAtAddress(pcRegister); switch (nextOpCode) { case OpCode.AALOAD: executeAaload(); break; case OpCode.ALOAD_0: executeAload_n(0); break; case OpCode.ASTORE_0: executeAstore_n(0); break; case OpCode.BIPUSH: operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1); stackMemorySection.setAtAddress(optopRegister, operand0); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(operand0)); optopRegister += 4; pcRegister += 2; break; // The BREAKPOINT opcode will serve as a stop sign for a running simulation. case OpCode.BREAKPOINT: stopButton.disable(); runButton.disable(); stepButton.disable(); resetButton.enable(); if (runner != null) { // If runner is not null, then this is probably the thread that // we want to stop. Therefore, as soon as stop has been executed, // nothing else will happen. So we must set runner to null before // we call runner.stop(). Therefore I copy runner to temp, assign // null to runner, and call stop() on temp. Thread temp = runner; runner = null; temp.stop(); } break; case OpCode.FCONST_0: stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 0)); stackMemorySection.setLogicalValueAtAddress(optopRegister, "0"); optopRegister += 4; ++pcRegister; break; case OpCode.FCONST_2: stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 2)); stackMemorySection.setLogicalValueAtAddress(optopRegister, "2"); optopRegister += 4; ++pcRegister; break; case OpCode.FLOAD_0: a = stackMemorySection.getAtAddress(varsRegister); stackMemorySection.setAtAddress(optopRegister, a); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fa)); optopRegister += 4; ++pcRegister; break; case OpCode.FMUL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); fb = Float.intBitsToFloat(b); fresult = fa * fb; result = Float.floatToIntBits(fresult); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult)); optopRegister += 4; ++pcRegister; break; case OpCode.FSTORE_0: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister, a); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(varsRegister, Float.toString(fa)); ++pcRegister; break; case OpCode.FSUB: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); fb = Float.intBitsToFloat(b); fresult = fb - fa; result = Float.floatToIntBits(fresult); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult)); optopRegister += 4; ++pcRegister; break; case OpCode.GOTO: operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; break; case OpCode.IADD: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a + b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.IAND: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a & b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.IASTORE: executeIastore(); break; case OpCode.ICONST_M1: stackMemorySection.setAtAddress(optopRegister, -1); stackMemorySection.setLogicalValueAtAddress(optopRegister, "-1"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_0: stackMemorySection.setAtAddress(optopRegister, 0); stackMemorySection.setLogicalValueAtAddress(optopRegister, "0"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_1: stackMemorySection.setAtAddress(optopRegister, 1); stackMemorySection.setLogicalValueAtAddress(optopRegister, "1"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_2: stackMemorySection.setAtAddress(optopRegister, 2); stackMemorySection.setLogicalValueAtAddress(optopRegister, "2"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_3: stackMemorySection.setAtAddress(optopRegister, 3); stackMemorySection.setLogicalValueAtAddress(optopRegister, "3"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_4: stackMemorySection.setAtAddress(optopRegister, 4); stackMemorySection.setLogicalValueAtAddress(optopRegister, "4"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_5: stackMemorySection.setAtAddress(optopRegister, 5); stackMemorySection.setLogicalValueAtAddress(optopRegister, "5"); optopRegister += 4; ++pcRegister; break; case OpCode.IFNE: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); // If a != 0 jump, else go on if (a != 0) { operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; } else { pcRegister += 3; } break; case OpCode.IF_ICMPLT: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); // If b < a jump, else go on if (b < a) { operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; } else { pcRegister += 3; } break; case OpCode.IINC: operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 2); a = stackMemorySection.getAtAddress(varsRegister + (operand0 * 4)); a += operand1; stackMemorySection.setAtAddress(varsRegister + (operand0 * 4), a); stackMemorySection.setLogicalValueAtAddress(varsRegister + (operand0 * 4), Integer.toString(a)); pcRegister += 3; break; case OpCode.ILOAD_0: a = stackMemorySection.getAtAddress(varsRegister); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_1: a = stackMemorySection.getAtAddress(varsRegister + 4); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_2: a = stackMemorySection.getAtAddress(varsRegister + 8); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_3: a = stackMemorySection.getAtAddress(varsRegister + 12); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.IMUL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a * b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.INT2BYTE: a = stackMemorySection.getAtAddress(optopRegister - 4); a = (byte) a; stackMemorySection.setAtAddress(optopRegister - 4, a); stackMemorySection.setLogicalValueAtAddress(optopRegister - 4, Integer.toString(a)); ++pcRegister; break; case OpCode.IOR: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a | b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.ISHL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = b << (a & 0x1f); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.ISTORE_0: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister, a); stackMemorySection.setLogicalValueAtAddress(varsRegister, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_1: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 4, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 4, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_2: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 8, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 8, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_3: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 12, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 12, Integer.toString(a)); ++pcRegister; break; case OpCode.IXOR: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a ^ b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.MULTIANEWARRAY: executeMultianewarray(); pcRegister += 4; break; } }
From source file:edu.uci.ics.hivesterix.serde.lazy.LazySerDe.java
/** * A recursive function that serialize an object to a byte buffer based on * its object inspector.//from w w w . j a v a2 s .c o m * * @param byteStream * the byte stream storing the serialization data * @param obj * the object to serialize * @param objInspector * the object inspector */ private void serialize(Output byteStream, Object obj, ObjectInspector objInspector) { // do nothing for null object if (null == obj) { return; } switch (objInspector.getCategory()) { case PRIMITIVE: { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) objInspector; switch (poi.getPrimitiveCategory()) { case VOID: { return; } case BOOLEAN: { boolean v = ((BooleanObjectInspector) poi).get(obj); byteStream.write((byte) (v ? 1 : 0)); return; } case BYTE: { ByteObjectInspector boi = (ByteObjectInspector) poi; byte v = boi.get(obj); byteStream.write(v); return; } case SHORT: { ShortObjectInspector spoi = (ShortObjectInspector) poi; short v = spoi.get(obj); byteStream.write((byte) (v >> 8)); byteStream.write((byte) (v)); return; } case INT: { IntObjectInspector ioi = (IntObjectInspector) poi; int v = ioi.get(obj); LazyUtils.writeVInt(byteStream, v); return; } case LONG: { LongObjectInspector loi = (LongObjectInspector) poi; long v = loi.get(obj); LazyUtils.writeVLong(byteStream, v); return; } case FLOAT: { FloatObjectInspector foi = (FloatObjectInspector) poi; int v = Float.floatToIntBits(foi.get(obj)); byteStream.write((byte) (v >> 24)); byteStream.write((byte) (v >> 16)); byteStream.write((byte) (v >> 8)); byteStream.write((byte) (v)); return; } case DOUBLE: { DoubleObjectInspector doi = (DoubleObjectInspector) poi; long v = Double.doubleToLongBits(doi.get(obj)); byteStream.write((byte) (v >> 56)); byteStream.write((byte) (v >> 48)); byteStream.write((byte) (v >> 40)); byteStream.write((byte) (v >> 32)); byteStream.write((byte) (v >> 24)); byteStream.write((byte) (v >> 16)); byteStream.write((byte) (v >> 8)); byteStream.write((byte) (v)); return; } case STRING: { StringObjectInspector soi = (StringObjectInspector) poi; Text t = soi.getPrimitiveWritableObject(obj); /* write byte size of the string which is a vint */ int length = t.getLength(); LazyUtils.writeVInt(byteStream, length); /* write string itself */ byte[] data = t.getBytes(); byteStream.write(data, 0, length); return; } default: { throw new RuntimeException("Unrecognized type: " + poi.getPrimitiveCategory()); } } } case LIST: { ListObjectInspector loi = (ListObjectInspector) objInspector; ObjectInspector eoi = loi.getListElementObjectInspector(); // 1/ reserve spaces for the byte size of the list // which is a integer and takes four bytes int byteSizeStart = byteStream.getCount(); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); int listStart = byteStream.getCount(); // 2/ write the size of the list as a VInt int size = loi.getListLength(obj); LazyUtils.writeVInt(byteStream, size); // 3/ write the null bytes byte nullByte = 0; for (int eid = 0; eid < size; eid++) { // set the bit to 1 if an element is not null if (null != loi.getListElement(obj, eid)) { nullByte |= 1 << (eid % 8); } // store the byte every eight elements or // if this is the last element if (7 == eid % 8 || eid == size - 1) { byteStream.write(nullByte); nullByte = 0; } } // 4/ write element by element from the list for (int eid = 0; eid < size; eid++) { serialize(byteStream, loi.getListElement(obj, eid), eoi); } // 5/ update the list byte size int listEnd = byteStream.getCount(); int listSize = listEnd - listStart; byte[] bytes = byteStream.getData(); bytes[byteSizeStart] = (byte) (listSize >> 24); bytes[byteSizeStart + 1] = (byte) (listSize >> 16); bytes[byteSizeStart + 2] = (byte) (listSize >> 8); bytes[byteSizeStart + 3] = (byte) (listSize); return; } case MAP: { MapObjectInspector moi = (MapObjectInspector) objInspector; ObjectInspector koi = moi.getMapKeyObjectInspector(); ObjectInspector voi = moi.getMapValueObjectInspector(); Map<?, ?> map = moi.getMap(obj); // 1/ reserve spaces for the byte size of the map // which is a integer and takes four bytes int byteSizeStart = byteStream.getCount(); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); int mapStart = byteStream.getCount(); // 2/ write the size of the map which is a VInt int size = map.size(); LazyUtils.writeVInt(byteStream, size); // 3/ write the null bytes int b = 0; byte nullByte = 0; for (Map.Entry<?, ?> entry : map.entrySet()) { // set the bit to 1 if a key is not null if (null != entry.getKey()) { nullByte |= 1 << (b % 8); } else if (!nullMapKey) { nullMapKey = true; LOG.warn("Null map key encountered! Ignoring similar problems."); } b++; // set the bit to 1 if a value is not null if (null != entry.getValue()) { nullByte |= 1 << (b % 8); } b++; // write the byte to stream every 4 key-value pairs // or if this is the last key-value pair if (0 == b % 8 || b == size * 2) { byteStream.write(nullByte); nullByte = 0; } } // 4/ write key-value pairs one by one for (Map.Entry<?, ?> entry : map.entrySet()) { serialize(byteStream, entry.getKey(), koi); serialize(byteStream, entry.getValue(), voi); } // 5/ update the byte size of the map int mapEnd = byteStream.getCount(); int mapSize = mapEnd - mapStart; byte[] bytes = byteStream.getData(); bytes[byteSizeStart] = (byte) (mapSize >> 24); bytes[byteSizeStart + 1] = (byte) (mapSize >> 16); bytes[byteSizeStart + 2] = (byte) (mapSize >> 8); bytes[byteSizeStart + 3] = (byte) (mapSize); return; } case STRUCT: { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes int byteSizeStart = byteStream.getCount(); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); byteStream.write((byte) 0); int structStart = byteStream.getCount(); // 2/ serialize the struct serializeStruct(byteStream, obj, (StructObjectInspector) objInspector); // 3/ update the byte size of the struct int structEnd = byteStream.getCount(); int structSize = structEnd - structStart; byte[] bytes = byteStream.getData(); bytes[byteSizeStart] = (byte) (structSize >> 24); bytes[byteSizeStart + 1] = (byte) (structSize >> 16); bytes[byteSizeStart + 2] = (byte) (structSize >> 8); bytes[byteSizeStart + 3] = (byte) (structSize); return; } default: { throw new RuntimeException("Unrecognized type: " + objInspector.getCategory()); } } }
From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileRandomAccessContent.java
/** * {@inheritDoc}//from w ww . jav a 2s . com */ public void writeFloat(final float _value) throws IOException { writeInt(Float.floatToIntBits(_value)); }
From source file:w2v.WordToVec.java
private void writeFloat(float f, DataOutputStream out) throws IOException { int v = Float.floatToIntBits(f); out.write((v >>> 0) & 0xFF); out.write((v >>> 8) & 0xFF); out.write((v >>> 16) & 0xFF); out.write((v >>> 24) & 0xFF); }