当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.shiftRight方法代码示例

本文整理汇总了Java中java.math.BigInteger.shiftRight方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.shiftRight方法的具体用法?Java BigInteger.shiftRight怎么用?Java BigInteger.shiftRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.shiftRight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addDesParity

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Expands a 7-byte array into an 8-byte array that contains parity bits
 * The binary format of a cryptographic key is:
 *     (B1,B2,...,B7,P1,B8,...B14,P2,B15,...,B49,P7,B50,...,B56,P8)
 * where (B1,B2,...,B56) are the independent bits of a DES key and
 * (PI,P2,...,P8) are reserved for parity bits computed on the preceding
 * seven independent bits and set so that the parity of the octet is odd,
 * i.e., there is an odd number of "1" bits in the octet.
 */
private static byte[] addDesParity(byte[] input, int offset, int len) {
    if (len != 7)
        throw new IllegalArgumentException(
            "Invalid length of DES Key Value:" + len);

    byte[] raw = new byte[7];
    System.arraycopy(input, offset, raw, 0, len);

    byte[] result = new byte[8];
    BigInteger in = new BigInteger(raw);

    // Shift 7 bits each time into a byte
    for (int i=result.length-1; i>=0; i--) {
        result[i] = in.and(MASK).toByteArray()[0];
        result[i] <<= 1;         // make room for parity bit
        in = in.shiftRight(7);
    }
    setParityBit(result);
    return result;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:DigestMD5Base.java

示例2: writeField

import java.math.BigInteger; //导入方法依赖的package包/类
private void writeField(
    OutputStream    out,
    BigInteger      fieldValue)
    throws IOException
{
    int byteCount = (fieldValue.bitLength()+6)/7;
    if (byteCount == 0)
    {
        out.write(0);
    }
    else
    {
        BigInteger tmpValue = fieldValue;
        byte[] tmp = new byte[byteCount];
        for (int i = byteCount-1; i >= 0; i--)
        {
            tmp[i] = (byte) ((tmpValue.intValue() & 0x7f) | 0x80);
            tmpValue = tmpValue.shiftRight(7);
        }
        tmp[byteCount-1] &= 0x7f;
        out.write(tmp);
    }

}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:25,代码来源:DERObjectIdentifier.java

示例3: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) {

        Scanner scann = new Scanner(System.in);
        String inputNumber = scann.nextLine();

        /*BigInteger mask = BigInteger.valueOf(7L);
        mask = mask.shiftLeft(61);*/
        BigInteger mask = new  BigInteger("e000000000000000", 16);
        BigInteger num = new BigInteger(inputNumber);

        // System.out.printf("%16s -> %s%n", "mask length", mask.toString(2).length());
        // System.out.printf("%16s -> %s%n", "binary mask",mask.toString(2));
        // System.out.printf("%16s -> %s%n", "binary num",num.toString(2));

        while (mask.compareTo(BigInteger.valueOf(7L)) >= 0){
            //System.out.printf("%16s -> %s%n", "mask & num", mask.and(num).toString(2));
            boolean treeConsecutiveOnes = Objects.equals(num.and(mask), mask);
            boolean treeConsecutiveZeroes = Objects.equals(num.and(mask), BigInteger.ZERO);
            if(treeConsecutiveOnes || treeConsecutiveZeroes){
                if(treeConsecutiveOnes){
                    //num &= (~mask)
                    num = num.andNot(mask);
                    //System.out.printf("%16s -> %s%n", "num &= (~mask)", num.toString(2));
                } else {
                    // num |= mask
                    num = num.or(mask);
                    //System.out.printf("%16s -> %s%n", "num |= mask", num.toString(2));
                }
                // move mask right
                mask = mask.shiftRight(3);
                //System.out.printf("%16s -> %s%n", "mask >> 3 ", mask.toString(2));
            } else {
                mask = mask.shiftRight(1);
                //System.out.printf("%16s -> %s%n","mask >> 1", mask.toString(2));
            }
        }
        System.out.println(num);
    }
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:39,代码来源:p01_BitFlipper.java

示例4: transform

import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
	double floatValue;
	
	if (value.getLSB() != null) {
		BigInteger val = parse(value, result);
		
		if (!value.mask().equals(BigInteger.ZERO))
			val = val.and(value.mask()); 
		
		if (!value.shift().equals(0))
			val = val.shiftRight(value.shift());
		
		if (value.getSigned() && val.bitLength()==(value.size()*4)) {
			BigInteger complement = new BigInteger(new String(new char[value.size()]).replace("\0", "F"),16);
			val = val.subtract(complement);
		}
		
		if (!objectCache.getTransformData()) {
			int intValue = val.intValue();
			return String.valueOf(intValue);
		}
		
		floatValue = val.doubleValue();
	} else {
		floatValue = Float.parseFloat(result);
	}
	
	if (!value.base().equals(0))
		floatValue = Math.pow(value.base(), floatValue);
	floatValue = floatValue * value.scale();
	floatValue = floatValue + value.offset();
	
	if (value.getType().toLowerCase().equals("f") || value.getType().toLowerCase().equals("float"))
		return String.valueOf(floatValue);
	return String.valueOf(Math.round(floatValue));
}
 
开发者ID:edgexfoundry,项目名称:device-modbus,代码行数:37,代码来源:ObjectTransform.java

示例5: numBytes

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate the number of bytes need
 * to encode the number
 *
 * @param val - number
 *
 * @return number of min bytes used to encode the number
 */
public static int numBytes(String val) {

  BigInteger bInt = new BigInteger(val);
  int bytes = 0;

  while (!bInt.equals(BigInteger.ZERO)) {
    bInt = bInt.shiftRight(8);
    ++bytes;
  }
  if (bytes == 0) ++bytes;
  return bytes;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:ByteUtil.java

示例6: numBytes

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate the number of bytes need
 * to encode the number
 *
 * @param val - number
 * @return number of min bytes used to encode the number
 */
public static int numBytes(String val) {

    BigInteger bInt = new BigInteger(val);
    int bytes = 0;

    while (!bInt.equals(BigInteger.ZERO)) {
        bInt = bInt.shiftRight(8);
        ++bytes;
    }
    if (bytes == 0) ++bytes;
    return bytes;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:20,代码来源:ByteUtil.java

示例7: write

import java.math.BigInteger; //导入方法依赖的package包/类
private static void write(OutputStream stream, BigInteger v) throws IOException {
    _assert(v);
    v = v.and(UNSIGNED_LONG_MAX_VALUE);
    BigInteger i = BigInteger.valueOf(-128);
    BigInteger BIX7F = BigInteger.valueOf(0x7f);
    BigInteger BIX80 = BigInteger.valueOf(0x80);
    while (!v.and(i).equals(BigInteger.ZERO)) {
        stream.write(v.and(BIX7F).or(BIX80).intValue());
        v = v.shiftRight(7);
    }

    stream.write(v.byteValue());
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:14,代码来源:VarInt.java

示例8: encodeZigZag64

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * @param v Signed long
 * @return Unsigned encoded long
 */
public static BigInteger encodeZigZag64(long v) {
    BigInteger origin = BigInteger.valueOf(v);
    BigInteger left = origin.shiftLeft(1);
    BigInteger right = origin.shiftRight(63);
    return left.xor(right);
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:11,代码来源:VarInt.java

示例9: logBigInteger

import java.math.BigInteger; //导入方法依赖的package包/类
public static double logBigInteger(BigInteger val) {
    int blex = val.bitLength() - 1022; // any value in 60..1023 is ok
    if(blex > 0) {
        val = val.shiftRight(blex);
    }
    double res = Math.log(val.doubleValue());
    return blex > 0 ? res + blex * LOG2 : res;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:9,代码来源:JBigNumber.java

示例10: writeUnsignedBigInteger

import java.math.BigInteger; //导入方法依赖的package包/类
private static void writeUnsignedBigInteger(ByteBuf buf, BigInteger value) {
    do {
        buf.writeByte(value.and(BINT_127).or(BINT_128).byteValue());
        value = value.shiftRight(SHIFT_AMOUNT);
    } while (!value.and(BINT_NEG_128).equals(BigInteger.ZERO));
    buf.writeByte(value.byteValue());
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:8,代码来源:ByteBufUtils.java

示例11: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main()throws IOException
{
    BufferedReader dr=new BufferedReader(new InputStreamReader(System.in));
    
    System.out.println("enter the number");
    String n=dr.readLine();
    BigInteger a=new BigInteger("4");
    BigInteger b=a.shiftRight(3);
    
    System.out.println(b);
}
 
开发者ID:shikhar29111996,项目名称:Java-programs,代码行数:12,代码来源:shift_right.java

示例12: createEncryptionGroup

import java.math.BigInteger; //导入方法依赖的package包/类
private EncryptionGroup createEncryptionGroup(BigInteger p) {
    log.info("creating encryption group");
    EncryptionGroup encryptionGroup = null;

    while (encryptionGroup == null) {
        if (!p.isProbablePrime(100)) {
            log.info("p is not prime...");
            continue;
        }

        BigInteger pMinusOne = p.subtract(ONE);
        BigInteger q = pMinusOne.shiftRight(1);
        if (!q.isProbablePrime(100)) {
            log.info("q is not prime...");
        }

        BigInteger g = getGenerator(q, p, pMinusOne);

        BigInteger h = randomGenerator.randomInGq(new EncryptionGroup(p, q, g, TWO));

        try {
            encryptionGroup = new EncryptionGroup(p, q, g, h);
        } catch (IllegalArgumentException e) {
            log.warn("Encryption group creation failed", e);
            encryptionGroup = null;
        }
    }
    log.info("encryption group created: " + encryptionGroup);
    return encryptionGroup;
}
 
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-protocol-poc,代码行数:31,代码来源:Simulation.java

示例13: decodeZigZag64

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * @param v Unsigned encoded long
 * @return Unsigned decoded long
 */
public static BigInteger decodeZigZag64(BigInteger v) {
    _assert(v);
    BigInteger left = v.shiftRight(1);
    BigInteger right = v.and(BigInteger.ONE).negate();
    return left.xor(right);
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:11,代码来源:VarInt.java

示例14: windowNaf

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Computes the Window NAF (non-adjacent Form) of an integer.
 * @param width The width <code>w</code> of the Window NAF. The width is
 * defined as the minimal number <code>w</code>, such that for any
 * <code>w</code> consecutive digits in the resulting representation, at
 * most one is non-zero.
 * @param k The integer of which the Window NAF is computed.
 * @return The Window NAF of the given width, such that the following holds:
 * <code>k = &sum;<sub>i=0</sub><sup>l-1</sup> k<sub>i</sub>2<sup>i</sup>
 * </code>, where the <code>k<sub>i</sub></code> denote the elements of the
 * returned <code>byte[]</code>.
 */
public byte[] windowNaf(byte width, BigInteger k)
{
    // The window NAF is at most 1 element longer than the binary
    // representation of the integer k. byte can be used instead of short or
    // int unless the window width is larger than 8. For larger width use
    // short or int. However, a width of more than 8 is not efficient for
    // m = log2(q) smaller than 2305 Bits. Note: Values for m larger than
    // 1000 Bits are currently not used in practice.
    byte[] wnaf = new byte[k.bitLength() + 1];

    // 2^width as short and BigInteger
    short pow2wB = (short)(1 << width);
    BigInteger pow2wBI = BigInteger.valueOf(pow2wB);

    int i = 0;

    // The actual length of the WNAF
    int length = 0;

    // while k >= 1
    while (k.signum() > 0)
    {
        // if k is odd
        if (k.testBit(0))
        {
            // k mod 2^width
            BigInteger remainder = k.mod(pow2wBI);

            // if remainder > 2^(width - 1) - 1
            if (remainder.testBit(width - 1))
            {
                wnaf[i] = (byte)(remainder.intValue() - pow2wB);
            }
            else
            {
                wnaf[i] = (byte)remainder.intValue();
            }
            // wnaf[i] is now in [-2^(width-1), 2^(width-1)-1]

            k = k.subtract(BigInteger.valueOf(wnaf[i]));
            length = i;
        }
        else
        {
            wnaf[i] = 0;
        }

        // k = k/2
        k = k.shiftRight(1);
        i++;
    }

    length++;

    // Reduce the WNAF array to its actual length
    byte[] wnafShort = new byte[length];
    System.arraycopy(wnaf, 0, wnafShort, 0, length);
    return wnafShort;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:72,代码来源:WNafMultiplier.java

示例15: transform

import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
  double floatValue;

  // Do not perform transforms on non-numeric fields
  if (nonNumeric(value)) {
    return result;
  }

  if (value.getLSB() != null) {
    BigInteger val = parse(value, result);

    if (!value.mask().equals(BigInteger.ZERO)) {
      val = val.and(value.mask());
    }

    if (!value.shift().equals(0)) {
      val = val.shiftRight(value.shift());
    }

    if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
      BigInteger complement =
          new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
      val = val.subtract(complement);
    }

    if (!objectCache.getTransformData()) {
      int intValue = val.intValue();
      return String.valueOf(intValue);
    }

    floatValue = val.doubleValue();
  } else {
    floatValue = Float.parseFloat(result);
  }

  if (!value.base().equals(0)) {
    floatValue = Math.pow(value.base(), floatValue);
  }

  floatValue = floatValue * value.scale();
  floatValue = floatValue + value.offset();

  if (value.getType().toLowerCase().equals("f")
      || value.getType().toLowerCase().equals("float")) {
    return String.valueOf(floatValue);
  }

  return String.valueOf(Math.round(floatValue));
}
 
开发者ID:edgexfoundry,项目名称:device-mqtt,代码行数:50,代码来源:ObjectTransform.java


注:本文中的java.math.BigInteger.shiftRight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。