Java Unsigned Number Create unsignedVLQSize(int value)

Here you can find the source of unsignedVLQSize(int value)

Description

unsigned VLQ Size

License

Apache License

Declaration

static int unsignedVLQSize(int value) 

Method Source Code

//package com.java2s;
/*//  w w  w  .  j av a 2s  .  c o m
 * Copyright (c) 2011-2013 Spotify AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

public class Main {
    static int unsignedVLQSize(int value) {
        if (value < 1 << 7) {
            return 1;
        }
        if (value < 1 << 14) {
            return 2;
        }
        if (value < 1 << 21) {
            return 3;
        }
        if (value < 1 << 28) {
            return 4;
        }
        return 5;
    }

    static int unsignedVLQSize(long value) {
        if (value < 1L << 7) {
            return 1;
        }
        if (value < 1L << 14) {
            return 2;
        }
        if (value < 1L << 21) {
            return 3;
        }
        if (value < 1L << 28) {
            return 4;
        }
        if (value < 1L << 35) {
            return 5;
        }
        if (value < 1L << 42) {
            return 6;
        }
        if (value < 1L << 49) {
            return 7;
        }
        if (value < 1L << 56) {
            return 8;
        }
        return 9;
    }
}

Related

  1. unsignedToSigned16(char value)
  2. unsignedToSigned8(char value)
  3. unsignedUnion2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)
  4. unsignedUpcast(short s)
  5. unsignedValue(byte signedByte)
  6. unsignedZerofill(Integer number, int offset)
  7. unsignL(byte value)