Java Integer to intToASN1(byte[] d, int idx, int val)

Here you can find the source of intToASN1(byte[] d, int idx, int val)

Description

Output an length or integer value in ASN.1 Does NOT output the tag e.g.

License

Open Source License

Parameter

Parameter Description
val 0-65535

Return

the new index

Declaration

public static int intToASN1(byte[] d, int idx, int val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//ww w .  j ava2  s  . c  o m
     *  Output an length or integer value in ASN.1
     *  Does NOT output the tag e.g. 0x02 / 0x30
     *
     *  @param val 0-65535
     *  @return the new index
     *  @since 0.9.25
     */
    public static int intToASN1(byte[] d, int idx, int val) {
        if (val < 0 || val > 65535)
            throw new IllegalArgumentException("fixme length " + val);
        if (val > 127) {
            if (val > 255) {
                d[idx++] = (byte) 0x82;
                d[idx++] = (byte) (val >> 8);
            } else {
                d[idx++] = (byte) 0x81;
            }
        }
        d[idx++] = (byte) val;
        return idx;
    }
}

Related

  1. intTo2LengthBytes(int i)
  2. intTo2UnsignedBytes(int val)
  3. intTo8HexString(int i)
  4. intToAlgebraicLoc(int loc)
  5. intToAlpha(Integer no)
  6. intToBase32(int n)
  7. intToBasicType(int i, Class clazz)
  8. intToBcd(int src, int len, int flag)
  9. intToBigEndian(int value, byte[] array, int index)