# %whex() function

The %whex() function writes to the file
specified by *file.descriptor* returned by a previous
call to %open(), %creat(), or %dup() a string of bytes resulting from converting the
ASCII string variable into binary.

## Syntax

```
byte.count = %whex(file.descriptor, var)
```

## Description

Two digits are converted into
one eight bit binary character. *var* is assumed
to contain only hexadecimal characters 0 to 9, A to F or a to f. The
function returns the number of bytes actually written or -1 if an
error occurred. The size written to the file is the size of var divided by 2. This function is the reverse of %rdhex().

## Example(s)

```
* Write "eof"x’ff’ on device
n=%whex(fd, oconv("eof","mx"):’FF’)
```

## See also

- [%creat() function](https://d3codex.com/pickbasic-flashbasic/percent-creat-function/)
- [%dup() function](https://d3codex.com/pickbasic-flashbasic/percent-dup-function/)
- [%open() function](https://d3codex.com/pickbasic-flashbasic/percent-open-function/)
- [%rdhex() function](https://d3codex.com/pickbasic-flashbasic/percent-rdhex-function/)
- [%write() function](https://d3codex.com/pickbasic-flashbasic/percent-write-function/)
- [FlashBASIC C functions overview](https://d3codex.com/pickbasic-flashbasic/flashbasic-c-functions-overview/)
- [cfunction statement](https://d3codex.com/pickbasic-flashbasic/cfunction-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/percent-whex-function/ - part of the D3Codex reference.
