Here you can find the source of encodeBigIntNoTypeCode(BigInteger value)
static byte[] encodeBigIntNoTypeCode(BigInteger value)
//package com.java2s; /**//from w ww . ja v a 2 s . com * Copyright (C) 2009-2013 FoundationDB, LLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.math.BigInteger; public class Main { static byte[] encodeBigIntNoTypeCode(BigInteger value) { byte[] bytes = value.toByteArray(); return floatingPointCoding(bytes, true); } /** * For encoding: if the sign bit is 1, flips all bits in the {@code byte[]}; * else, just flips the sign bit. * <br><br> * For decoding: if the sign bit is 1, flips all bits in the {@code byte[]}; * else, just flips the sign bit. * * @param bytes - a Big-Endian IEEE binary representation of float, double, or BigInteger * @param encode - if true, encodes; if false, decodes * @return the encoded {@code byte[]} */ static byte[] floatingPointCoding(byte[] bytes, boolean encode) { if (encode && (bytes[0] & (byte) 0x80) != (byte) 0x00) { for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (bytes[i] ^ 0xff); } } else if (!encode && (bytes[0] & (byte) 0x80) != (byte) 0x80) { for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (bytes[i] ^ 0xff); } } else { bytes[0] = (byte) (0x80 ^ bytes[0]); } return bytes; } }