private static short codeUnit(int nibble0, int nibble1, int nibble2, int nibble3) {
    if ((nibble0 & ~0xf) != 0) {
      throw new IllegalArgumentException("bogus nibble0");
    }

    if ((nibble1 & ~0xf) != 0) {
      throw new IllegalArgumentException("bogus nibble1");
    }

    if ((nibble2 & ~0xf) != 0) {
      throw new IllegalArgumentException("bogus nibble2");
    }

    if ((nibble3 & ~0xf) != 0) {
      throw new IllegalArgumentException("bogus nibble3");
    }

    return (short) (nibble0 | (nibble1 << 4) | (nibble2 << 8) | (nibble3 << 12));
  }
Helper method that encodes any of the three-unit register-range formats.
android/android_framework/dex-maker/src/main/java/com/android/dx/io/instructions/InstructionCodec.java