# BCDTOHEX

The BCDTOHEX function converts an item from binary coded decimal (BCD) format to hexadecimal format. The binary value that is returned always has the high-order byte first, regardless of the operating system. This is useful for testing a specific bit position for a specific value.

.

**Syntax:**

BCDTOHEX (single-text-expression, single-integer-expression)- Meaning:
- BCDTOHEX (BCD_item_to_convert, length_of_output)
- Returns:
- A single binary bytestream

When using the BCDTOHEX function, the input argument is converted from BCD format to its binary value.

Numbers in BCD format have two decimal digits in each byte. Each half-byte, therefore, can contain a binary value from 0000 (which represents the digit 0) through 1001 (which represents the digit 9). Based on this definition, the following behavior applies:

- If any half-byte of the BCD number contains the binary values 1101 or 1111, that half-byte is ignored.
- If any half-byte contains the binary values 1010, 1011, 1100, or 1110, the output of the function is "none".

The length of the output argument is specified as the value of the second input argument. The length must be 1, 2, or 4. If it is any other value, the length is assumed to be 2.

## Examples

- You can use BCDTOHEX to test a specific bit position for a specific value. For example, BCDTOHEX is useful when the BCD value represents flag bits. The conversion performed by BCDTOHEX results in a predictable location for the flag bits across operating systems where the bytes might otherwise be reversed.
- TESTON (BCDTOHEX (
ProcessIndicator, 2) 10)
Tests for the x`0040' bit in a two-byte result.

Note: This same test, using BCDTOINT on a PC, tests the x`4000' bit.

## Related functions

- BCDTOTEXT
- BCDTOINT
- TEXTTOBCD