Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/util/HexFormat#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/HexFormat#inhmethods)

# HexFormat

` public final class HexFormat `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.HexFormat |

<br />

*** ** * ** ***

`HexFormat` converts between bytes and chars and hex-encoded strings which may include additional formatting markup such as prefixes, suffixes, and delimiters.

There are two factories of `HexFormat` with preset parameters `https://developer.android.com/reference/java/util/HexFormat#of()` and `https://developer.android.com/reference/java/util/HexFormat#ofDelimiter(java.lang.String)`. For other parameter combinations the `withXXX` methods return copies of `HexFormat` modified `https://developer.android.com/reference/java/util/HexFormat#withPrefix(java.lang.String)`, `https://developer.android.com/reference/java/util/HexFormat#withSuffix(java.lang.String)`, `https://developer.android.com/reference/java/util/HexFormat#withDelimiter(java.lang.String)` or choice of `https://developer.android.com/reference/java/util/HexFormat#withUpperCase()` or `https://developer.android.com/reference/java/util/HexFormat#withLowerCase()` parameters.

For primitive to hexadecimal string conversions the `toHexDigits` methods include `https://developer.android.com/reference/java/util/HexFormat#toHexDigits(byte)`, `https://developer.android.com/reference/java/util/HexFormat#toHexDigits(int)`, and `https://developer.android.com/reference/java/util/HexFormat#toHexDigits(long)`, etc. The default is to use lowercase characters `"0-9","a-f"`. For conversions producing uppercase hexadecimal the characters are `"0-9","A-F"`. Only the `https://developer.android.com/reference/java/util/HexFormat#isUpperCase()` parameter is considered; the delimiter, prefix and suffix are not used.

For hexadecimal string to primitive conversions the `fromHexDigits` methods include `https://developer.android.com/reference/java/util/HexFormat#fromHexDigits(java.lang.CharSequence)`, `https://developer.android.com/reference/java/util/HexFormat#fromHexDigitsToLong(java.lang.CharSequence)`, and `https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)` converts a single character or codepoint. For conversions from hexadecimal characters the digits and uppercase and lowercase characters in `"0-9", "a-f", and "A-F"` are converted to corresponding values `0-15`. The delimiter, prefix, suffix, and uppercase parameters are not used.

For byte array to formatted hexadecimal string conversions the `formatHex` methods include `https://developer.android.com/reference/java/util/HexFormat#formatHex(byte[])` and `https://developer.android.com/reference/java/util/HexFormat#formatHex(A,%20byte[])`. The formatted output is a string or is appended to an `https://developer.android.com/reference/java/lang/Appendable` such as `https://developer.android.com/reference/java/lang/StringBuilder` or `https://developer.android.com/reference/java/io/PrintStream`. Each byte value is formatted as the prefix, two hexadecimal characters from the uppercase or lowercase digits, and the suffix. A delimiter follows each formatted value, except the last. For conversions producing uppercase hexadecimal strings use `https://developer.android.com/reference/java/util/HexFormat#withUpperCase()`.

For formatted hexadecimal string to byte array conversions the `parseHex` methods include `https://developer.android.com/reference/java/util/HexFormat#parseHex(java.lang.CharSequence)` and `https://developer.android.com/reference/java/util/HexFormat#parseHex(char[],%20int,%20int)`. Each byte value is parsed from the prefix, two case insensitive hexadecimal characters, and the suffix. A delimiter follows each formatted value, except the last.

## Summary

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#delimiter()() ` Returns the delimiter between hexadecimal values in formatted hexadecimal strings. |
| ` boolean` | ` https://developer.android.com/reference/java/util/HexFormat#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Returns `true` if the other object is a `HexFormat` with the same parameters. |
| ` <A extends https://developer.android.com/reference/java/lang/Appendable> A` | ` https://developer.android.com/reference/java/util/HexFormat#formatHex(A,%20byte[])(A out, byte[] bytes) ` Appends formatted hexadecimal strings from a byte array to the `https://developer.android.com/reference/java/lang/Appendable`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#formatHex(byte[])(byte[] bytes) ` Returns a hexadecimal string formatted from a byte array. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#formatHex(byte[],%20int,%20int)(byte[] bytes, int fromIndex, int toIndex) ` Returns a hexadecimal string formatted from a byte array range. |
| ` <A extends https://developer.android.com/reference/java/lang/Appendable> A` | ` https://developer.android.com/reference/java/util/HexFormat#formatHex(A,%20byte[],%20int,%20int)(A out, byte[] bytes, int fromIndex, int toIndex) ` Appends formatted hexadecimal strings from a byte array range to the `https://developer.android.com/reference/java/lang/Appendable`. |
| ` static int` | ` https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)(int ch) ` Returns the value for the hexadecimal character or codepoint. |
| ` static int` | ` https://developer.android.com/reference/java/util/HexFormat#fromHexDigits(java.lang.CharSequence,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence string, int fromIndex, int toIndex) ` Returns the `int` value parsed from a string range of up to eight hexadecimal characters. |
| ` static int` | ` https://developer.android.com/reference/java/util/HexFormat#fromHexDigits(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence string) ` Returns the `int` value parsed from a string of up to eight hexadecimal characters. |
| ` static long` | ` https://developer.android.com/reference/java/util/HexFormat#fromHexDigitsToLong(java.lang.CharSequence,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence string, int fromIndex, int toIndex) ` Returns the long value parsed from a string range of up to sixteen hexadecimal characters. |
| ` static long` | ` https://developer.android.com/reference/java/util/HexFormat#fromHexDigitsToLong(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence string) ` Returns the long value parsed from a string of up to sixteen hexadecimal characters. |
| ` int` | ` https://developer.android.com/reference/java/util/HexFormat#hashCode()() ` Returns a hashcode for this `HexFormat`. |
| ` static boolean` | ` https://developer.android.com/reference/java/util/HexFormat#isHexDigit(int)(int ch) ` Returns `true` if the character is a valid hexadecimal character or codepoint. |
| ` boolean` | ` https://developer.android.com/reference/java/util/HexFormat#isUpperCase()() ` Returns `true` if the hexadecimal digits are uppercase, otherwise `false`. |
| ` static https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#of()() ` Returns a hexadecimal formatter with no delimiter and lowercase characters. |
| ` static https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#ofDelimiter(java.lang.String)(https://developer.android.com/reference/java/lang/String delimiter) ` Returns a hexadecimal formatter with the delimiter and lowercase characters. |
| ` byte[]` | ` https://developer.android.com/reference/java/util/HexFormat#parseHex(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence string) ` Returns a byte array containing hexadecimal values parsed from the string. |
| ` byte[]` | ` https://developer.android.com/reference/java/util/HexFormat#parseHex(java.lang.CharSequence,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence string, int fromIndex, int toIndex) ` Returns a byte array containing hexadecimal values parsed from a range of the string. |
| ` byte[]` | ` https://developer.android.com/reference/java/util/HexFormat#parseHex(char[],%20int,%20int)(char[] chars, int fromIndex, int toIndex) ` Returns a byte array containing hexadecimal values parsed from a range of the character array. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#prefix()() ` Returns the prefix used for each hexadecimal value in formatted hexadecimal strings. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#suffix()() ` Returns the suffix used for each hexadecimal value in formatted hexadecimal strings. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(short)(short value) ` Returns the four hexadecimal characters for the `short` value. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(byte)(byte value) ` Returns the two hexadecimal characters for the `byte` value. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(int)(int value) ` Returns the eight hexadecimal characters for the `int` value. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(char)(char value) ` Returns the four hexadecimal characters for the `char` value. |
| ` <A extends https://developer.android.com/reference/java/lang/Appendable> A` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(A,%20byte)(A out, byte value) ` Appends two hexadecimal characters for the byte value to the `https://developer.android.com/reference/java/lang/Appendable`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(long,%20int)(long value, int digits) ` Returns up to sixteen hexadecimal characters for the `long` value. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toHexDigits(long)(long value) ` Returns the sixteen hexadecimal characters for the `long` value. |
| ` char` | ` https://developer.android.com/reference/java/util/HexFormat#toHighHexDigit(int)(int value) ` Returns the hexadecimal character for the high 4 bits of the value considering it to be a byte. |
| ` char` | ` https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)(int value) ` Returns the hexadecimal character for the low 4 bits of the value considering it to be a byte. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/HexFormat#toString()() ` Returns a description of the formatter parameters for uppercase, delimiter, prefix, and suffix. |
| ` https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#withDelimiter(java.lang.String)(https://developer.android.com/reference/java/lang/String delimiter) ` Returns a copy of this `HexFormat` with the delimiter. |
| ` https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#withLowerCase()() ` Returns a copy of this `HexFormat` to use lowercase hexadecimal characters. |
| ` https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#withPrefix(java.lang.String)(https://developer.android.com/reference/java/lang/String prefix) ` Returns a copy of this `HexFormat` with the prefix. |
| ` https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#withSuffix(java.lang.String)(https://developer.android.com/reference/java/lang/String suffix) ` Returns a copy of this `HexFormat` with the suffix. |
| ` https://developer.android.com/reference/java/util/HexFormat` | ` https://developer.android.com/reference/java/util/HexFormat#withUpperCase()() ` Returns a copy of this `HexFormat` to use uppercase hexadecimal characters. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### delimiter

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String delimiter ()
```

Returns the delimiter between hexadecimal values in formatted hexadecimal strings.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the delimiter, non-null, may be empty `""` <br /> |

### equals

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object o)
```

Returns `true` if the other object is a `HexFormat` with the same parameters.

<br />

| Parameters ||
|---|---|
| `o` | `Object`: an object, may be null <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the other object is a `HexFormat` and the parameters uppercase, delimiter, prefix, and suffix are equal; otherwise `false` <br /> |

### formatHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public A formatHex (A out, 
                byte[] bytes)
```

Appends formatted hexadecimal strings from a byte array to the `https://developer.android.com/reference/java/lang/Appendable`. Each byte value is formatted as the prefix, two hexadecimal characters [selected from](https://developer.android.com/reference/java/util/HexFormat#isUpperCase()) uppercase or lowercase digits, and the suffix. A delimiter follows each formatted value, except the last. The formatted hexadecimal strings are appended in zero or more calls to the `https://developer.android.com/reference/java/lang/Appendable` methods.

<br />

| Parameters ||
|---|---|
| `out` | `A`: an `Appendable`, non-null <br /> |
| `bytes` | `byte`: a byte array <br /> |

| Returns ||
|---|---|
| `A` | the `Appendable` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/UncheckedIOException` | if an I/O exception occurs appending to the output |

### formatHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String formatHex (byte[] bytes)
```

Returns a hexadecimal string formatted from a byte array. Each byte value is formatted as the prefix, two hexadecimal characters [selected from](https://developer.android.com/reference/java/util/HexFormat#isUpperCase()) uppercase or lowercase digits, and the suffix. A delimiter follows each formatted value, except the last. The behavior is equivalent to `https://developer.android.com/reference/java/util/HexFormat#formatHex(byte[],%20int,%20int)`.

<br />

| Parameters ||
|---|---|
| `bytes` | `byte`: a non-null array of bytes <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string hexadecimal formatting of the byte array <br /> |

### formatHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String formatHex (byte[] bytes, 
                int fromIndex, 
                int toIndex)
```

Returns a hexadecimal string formatted from a byte array range. Each byte value is formatted as the prefix, two hexadecimal characters [selected from](https://developer.android.com/reference/java/util/HexFormat#isUpperCase()) uppercase or lowercase digits, and the suffix. A delimiter follows each formatted value, except the last.

<br />

| Parameters ||
|---|---|
| `bytes` | `byte`: a non-null array of bytes <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string hexadecimal formatting each byte of the array range <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the array range is out of bounds |

### formatHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public A formatHex (A out, 
                byte[] bytes, 
                int fromIndex, 
                int toIndex)
```

Appends formatted hexadecimal strings from a byte array range to the `https://developer.android.com/reference/java/lang/Appendable`. Each byte value is formatted as the prefix, two hexadecimal characters [selected from](https://developer.android.com/reference/java/util/HexFormat#isUpperCase()) uppercase or lowercase digits, and the suffix. A delimiter follows each formatted value, except the last. The formatted hexadecimal strings are appended in zero or more calls to the `https://developer.android.com/reference/java/lang/Appendable` methods.

<br />

| Parameters ||
|---|---|
| `out` | `A`: an `Appendable`, non-null <br /> |
| `bytes` | `byte`: a byte array, non-null <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive. <br /> |

| Returns ||
|---|---|
| `A` | the `Appendable` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/UncheckedIOException` | if an I/O exception occurs appending to the output |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the array range is out of bounds |

### fromHexDigit

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int fromHexDigit (int ch)
```

Returns the value for the hexadecimal character or codepoint. The value is:

- `(ch - '0')` for `'0'` through `'9'` inclusive,
- `(ch - 'A' + 10)` for `'A'` through `'F'` inclusive, and
- `(ch - 'a' + 10)` for `'a'` through `'f'` inclusive.

<br />

<br />

| Parameters ||
|---|---|
| `ch` | `int`: a character or codepoint <br /> |

| Returns ||
|---|---|
| `int` | the value `0-15` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if the codepoint is not a hexadecimal character |

### fromHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int fromHexDigits (CharSequence string, 
                int fromIndex, 
                int toIndex)
```

Returns the `int` value parsed from a string range of up to eight hexadecimal characters. The characters in the range `fromIndex` to `toIndex`, exclusive, are parsed from most significant to least significant using `https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)` to form an unsigned value. The value is zero extended to 32 bits and is returned as an `int`.

<br />

##### API Note:

- `https://developer.android.com/reference/java/lang/Integer#parseInt(java.lang.String,%20int)` and `https://developer.android.com/reference/java/lang/Integer#parseUnsignedInt(java.lang.String,%20int)` are similar but allow all Unicode hexadecimal digits defined by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. `HexFormat` uses only hexadecimal characters `"0-9"`, `"A-F"` and `"a-f"`. Signed hexadecimal strings can be parsed with `https://developer.android.com/reference/java/lang/Integer#parseInt(java.lang.String,%20int)`.

| Parameters ||
|---|---|
| `string` | `CharSequence`: a CharSequence containing the characters <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive. <br /> |

| Returns ||
|---|---|
| `int` | the value parsed from the string range <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if length of the range is greater than eight (8) or if any of the characters is not a hexadecimal character |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the range is out of bounds for the `CharSequence` |

### fromHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int fromHexDigits (CharSequence string)
```

Returns the `int` value parsed from a string of up to eight hexadecimal characters. The hexadecimal characters are parsed from most significant to least significant using `https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)` to form an unsigned value. The value is zero extended to 32 bits and is returned as an `int`.

<br />

##### API Note:

- `https://developer.android.com/reference/java/lang/Integer#parseInt(java.lang.String,%20int)` and `https://developer.android.com/reference/java/lang/Integer#parseUnsignedInt(java.lang.String,%20int)` are similar but allow all Unicode hexadecimal digits defined by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. `HexFormat` uses only hexadecimal characters `"0-9"`, `"A-F"` and `"a-f"`. Signed hexadecimal strings can be parsed with `https://developer.android.com/reference/java/lang/Integer#parseInt(java.lang.String,%20int)`.

| Parameters ||
|---|---|
| `string` | `CharSequence`: a CharSequence containing up to eight hexadecimal characters <br /> |

| Returns ||
|---|---|
| `int` | the value parsed from the string <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the string length is greater than eight (8) or if any of the characters is not a hexadecimal character |

### fromHexDigitsToLong

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long fromHexDigitsToLong (CharSequence string, 
                int fromIndex, 
                int toIndex)
```

Returns the long value parsed from a string range of up to sixteen hexadecimal characters. The characters in the range `fromIndex` to `toIndex`, exclusive, are parsed from most significant to least significant using `https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)` to form an unsigned value. The value is zero extended to 64 bits and is returned as a `long`.

<br />

##### API Note:

- `https://developer.android.com/reference/java/lang/Long#parseLong(java.lang.String,%20int)` and `https://developer.android.com/reference/java/lang/Long#parseUnsignedLong(java.lang.String,%20int)` are similar but allow all Unicode hexadecimal digits defined by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. `HexFormat` uses only hexadecimal characters `"0-9"`, `"A-F"` and `"a-f"`. Signed hexadecimal strings can be parsed with `https://developer.android.com/reference/java/lang/Long#parseLong(java.lang.String,%20int)`.

| Parameters ||
|---|---|
| `string` | `CharSequence`: a CharSequence containing the characters <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive. <br /> |

| Returns ||
|---|---|
| `long` | the value parsed from the string range <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the length of the range is greater than sixteen (16) or if any of the characters is not a hexadecimal character |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the range is out of bounds for the `CharSequence` |

### fromHexDigitsToLong

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long fromHexDigitsToLong (CharSequence string)
```

Returns the long value parsed from a string of up to sixteen hexadecimal characters. The hexadecimal characters are parsed from most significant to least significant using `https://developer.android.com/reference/java/util/HexFormat#fromHexDigit(int)` to form an unsigned value. The value is zero extended to 64 bits and is returned as a `long`.

<br />

##### API Note:

- `https://developer.android.com/reference/java/lang/Long#parseLong(java.lang.String,%20int)` and `https://developer.android.com/reference/java/lang/Long#parseUnsignedLong(java.lang.String,%20int)` are similar but allow all Unicode hexadecimal digits defined by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. `HexFormat` uses only hexadecimal characters `"0-9"`, `"A-F"` and `"a-f"`. Signed hexadecimal strings can be parsed with `https://developer.android.com/reference/java/lang/Long#parseLong(java.lang.String,%20int)`.

| Parameters ||
|---|---|
| `string` | `CharSequence`: a CharSequence containing up to sixteen hexadecimal characters <br /> |

| Returns ||
|---|---|
| `long` | the value parsed from the string <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the string length is greater than sixteen (16) or if any of the characters is not a hexadecimal character |

### hashCode

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hashcode for this `HexFormat`.

<br />

| Returns ||
|---|---|
| `int` | a hashcode for this `HexFormat` <br /> |

### isHexDigit

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isHexDigit (int ch)
```

Returns `true` if the character is a valid hexadecimal character or codepoint. The valid hexadecimal characters are:

- `'0' ('\u0030')` through `'9' ('\u0039')` inclusive,
- `'A' ('\u0041')` through `'F' ('\u0046')` inclusive, and
- `'a' ('\u0061')` through `'f' ('\u0066')` inclusive.

<br />

<br />

| Parameters ||
|---|---|
| `ch` | `int`: a codepoint <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the character is valid a hexadecimal character, otherwise `false` <br /> |

### isUpperCase

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isUpperCase ()
```

Returns `true` if the hexadecimal digits are uppercase, otherwise `false`.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the hexadecimal digits are uppercase, otherwise `false` <br /> |

### of

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static HexFormat of ()
```

Returns a hexadecimal formatter with no delimiter and lowercase characters. The delimiter, prefix, and suffix are empty. The methods `https://developer.android.com/reference/java/util/HexFormat#withDelimiter(java.lang.String)`, `https://developer.android.com/reference/java/util/HexFormat#withUpperCase()`, `https://developer.android.com/reference/java/util/HexFormat#withLowerCase()`, `https://developer.android.com/reference/java/util/HexFormat#withPrefix(java.lang.String)`, and `https://developer.android.com/reference/java/util/HexFormat#withSuffix(java.lang.String)` return copies of formatters with new parameters.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a hexadecimal formatter with no delimiter and lowercase characters <br /> |

### ofDelimiter

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static HexFormat ofDelimiter (String delimiter)
```

Returns a hexadecimal formatter with the delimiter and lowercase characters. The prefix and suffix are empty. The methods `https://developer.android.com/reference/java/util/HexFormat#withDelimiter(java.lang.String)`, `https://developer.android.com/reference/java/util/HexFormat#withUpperCase()`, `https://developer.android.com/reference/java/util/HexFormat#withLowerCase()`, `https://developer.android.com/reference/java/util/HexFormat#withPrefix(java.lang.String)`, and `https://developer.android.com/reference/java/util/HexFormat#withSuffix(java.lang.String)` return copies of formatters with new parameters.

<br />

| Parameters ||
|---|---|
| `delimiter` | `String`: a delimiter, non-null, may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a `https://developer.android.com/reference/java/util/HexFormat` with the delimiter and lowercase characters <br /> |

### parseHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] parseHex (CharSequence string)
```

Returns a byte array containing hexadecimal values parsed from the string. Each byte value is parsed from the prefix, two case insensitive hexadecimal characters, and the suffix. A delimiter follows each formatted value, except the last. The delimiters, prefixes, and suffixes strings must be present; they may be empty strings. A valid string consists only of the above format.

<br />

| Parameters ||
|---|---|
| `string` | `CharSequence`: a string containing the byte values with prefix, hexadecimal digits, suffix, and delimiters <br /> |

| Returns ||
|---|---|
| `byte[]` | a byte array with the values parsed from the string <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the prefix or suffix is not present for each byte value, the byte values are not hexadecimal characters, or if the delimiter is not present after all but the last byte value |

### parseHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] parseHex (CharSequence string, 
                int fromIndex, 
                int toIndex)
```

Returns a byte array containing hexadecimal values parsed from a range of the string. Each byte value is parsed from the prefix, two case insensitive hexadecimal characters, and the suffix. A delimiter follows each formatted value, except the last. The delimiters, prefixes, and suffixes strings must be present; they may be empty strings. A valid string consists only of the above format.

<br />

| Parameters ||
|---|---|
| `string` | `CharSequence`: a string range containing hexadecimal digits, delimiters, prefix, and suffix. <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive. <br /> |

| Returns ||
|---|---|
| `byte[]` | a byte array with the values parsed from the string range <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the prefix or suffix is not present for each byte value, the byte values are not hexadecimal characters, or if the delimiter is not present after all but the last byte value |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the string range is out of bounds |

### parseHex

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] parseHex (char[] chars, 
                int fromIndex, 
                int toIndex)
```

Returns a byte array containing hexadecimal values parsed from a range of the character array. Each byte value is parsed from the prefix, two case insensitive hexadecimal characters, and the suffix. A delimiter follows each formatted value, except the last. The delimiters, prefixes, and suffixes strings must be present; they may be empty strings. A valid character array range consists only of the above format.

<br />

| Parameters ||
|---|---|
| `chars` | `char`: a character array range containing an even number of hexadecimal digits, delimiters, prefix, and suffix. <br /> |
| `fromIndex` | `int`: the initial index of the range, inclusive <br /> |
| `toIndex` | `int`: the final index of the range, exclusive. <br /> |

| Returns ||
|---|---|
| `byte[]` | a byte array with the values parsed from the character array range <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the prefix or suffix is not present for each byte value, the byte values are not hexadecimal characters, or if the delimiter is not present after all but the last byte value |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the character array range is out of bounds |

### prefix

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String prefix ()
```

Returns the prefix used for each hexadecimal value in formatted hexadecimal strings.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the prefix, non-null, may be empty `""` <br /> |

### suffix

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String suffix ()
```

Returns the suffix used for each hexadecimal value in formatted hexadecimal strings.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the suffix, non-null, may be empty `""` <br /> |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (short value)
```

Returns the four hexadecimal characters for the `short` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `short`: a `short` value <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the four hexadecimal characters for the `short` value <br /> |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (byte value)
```

Returns the two hexadecimal characters for the `byte` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `byte`: a byte value <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the two hexadecimal characters for the byte value <br /> |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (int value)
```

Returns the eight hexadecimal characters for the `int` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `int`: an `int` value <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the eight hexadecimal characters for the `int` value <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Integer#toHexString(int)`

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (char value)
```

Returns the four hexadecimal characters for the `char` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `char`: a `char` value <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the four hexadecimal characters for the `char` value <br /> |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public A toHexDigits (A out, 
                byte value)
```

Appends two hexadecimal characters for the byte value to the `https://developer.android.com/reference/java/lang/Appendable`. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The hexadecimal characters are appended in one or more calls to the `https://developer.android.com/reference/java/lang/Appendable` methods. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `out` | `A`: an `Appendable`, non-null <br /> |
| `value` | `byte`: a byte value <br /> |

| Returns ||
|---|---|
| `A` | the `Appendable` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/UncheckedIOException` | if an I/O exception occurs appending to the output |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (long value, 
                int digits)
```

Returns up to sixteen hexadecimal characters for the `long` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `long`: a `long` value <br /> |
| `digits` | `int`: the number of hexadecimal digits to return, 0 to 16 <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the hexadecimal characters for the `long` value <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `digits` is negative or greater than 16 |

### toHexDigits

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toHexDigits (long value)
```

Returns the sixteen hexadecimal characters for the `long` value. Each nibble (4 bits) from most significant to least significant of the value is formatted as if by `https://developer.android.com/reference/java/util/HexFormat#toLowHexDigit(int)`. The delimiter, prefix and suffix are not used.

<br />

| Parameters ||
|---|---|
| `value` | `long`: a `long` value <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the sixteen hexadecimal characters for the `long` value <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Long#toHexString(long)`

### toHighHexDigit

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char toHighHexDigit (int value)
```

Returns the hexadecimal character for the high 4 bits of the value considering it to be a byte. If the parameter `https://developer.android.com/reference/java/util/HexFormat#isUpperCase()` is `true` the character returned for values `10-15` is uppercase `"A-F"`, otherwise the character returned is lowercase `"a-f"`. The values in the range `0-9` are returned as `"0-9"`.

<br />

| Parameters ||
|---|---|
| `value` | `int`: a value, only bits `4-7` of the value are used <br /> |

| Returns ||
|---|---|
| `char` | the hexadecimal character for the bits `4-7` of the value <br /> |

### toLowHexDigit

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char toLowHexDigit (int value)
```

Returns the hexadecimal character for the low 4 bits of the value considering it to be a byte. If the parameter `https://developer.android.com/reference/java/util/HexFormat#isUpperCase()` is `true` the character returned for values `10-15` is uppercase `"A-F"`, otherwise the character returned is lowercase `"a-f"`. The values in the range `0-9` are returned as `"0-9"`.

<br />

| Parameters ||
|---|---|
| `value` | `int`: a value, only the low 4 bits `0-3` of the value are used <br /> |

| Returns ||
|---|---|
| `char` | the hexadecimal character for the low 4 bits `0-3` of the value <br /> |

### toString

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a description of the formatter parameters for uppercase, delimiter, prefix, and suffix.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a description of this `HexFormat` <br /> |

### withDelimiter

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public HexFormat withDelimiter (String delimiter)
```

Returns a copy of this `HexFormat` with the delimiter.

<br />

| Parameters ||
|---|---|
| `delimiter` | `String`: the delimiter, non-null, may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a copy of this `HexFormat` with the delimiter <br /> |

### withLowerCase

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public HexFormat withLowerCase ()
```

Returns a copy of this `HexFormat` to use lowercase hexadecimal characters. The lowercase hexadecimal characters are `"0-9", "a-f"`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a copy of this `HexFormat` with lowercase hexadecimal characters <br /> |

### withPrefix

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public HexFormat withPrefix (String prefix)
```

Returns a copy of this `HexFormat` with the prefix.

<br />

| Parameters ||
|---|---|
| `prefix` | `String`: a prefix, non-null, may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a copy of this `HexFormat` with the prefix <br /> |

### withSuffix

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public HexFormat withSuffix (String suffix)
```

Returns a copy of this `HexFormat` with the suffix.

<br />

| Parameters ||
|---|---|
| `suffix` | `String`: a suffix, non-null, may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a copy of this `HexFormat` with the suffix <br /> |

### withUpperCase

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public HexFormat withUpperCase ()
```

Returns a copy of this `HexFormat` to use uppercase hexadecimal characters. The uppercase hexadecimal characters are `"0-9", "A-F"`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/HexFormat` | a copy of this `HexFormat` with uppercase hexadecimal characters <br /> |