Reference Guide > B Routines > BYTE Function
  

BYTE Function
The BYTE function can be used to do the following:
*Convert an expression to byte data type.
*Extract data from an expression and place it in a byte scalar or array.
enabled.
Usage
This form is used to convert data.
result = BYTE(expr)
This form is used to extract data.
result = BYTE(expr, offset [, dim1, ... , dimn])
Input Parameters
To convert data:
expr—The expression to be converted.
To extract data:
expr—The expression from which to extract data.
offset—The offset, in bytes, from the beginning of expr to where the extraction is to begin. If present, causes BYTE to extract data, not convert it.
dimi—(optional) The dimensions of the result. May be any scalar expression. Up to eight dimensions may be specified.
Returned Value
For data conversion:
result—A copy of expr converted to byte data type. The result has the same size and structure (scalar or array) as expr.
For extracting data:
result—A copy of only part of expr—the part that is defined by the offset and dim input parameters. The result has the size and structure of the specified dimensions and is of the byte data type. If no dimensions are specified, the result is scalar.
Keywords
None.
Discussion
BYTE can be useful in a variety of applications—for example, in hexadecimal math, when you want to be certain that you are working with a byte value to ensure that any comparison you make is valid.
If expr is of type string, each character is converted to its ASCII value and placed into a vector. In other words, each vector element is the ASCII character code of the corresponding character in the string.
If expr is not of type string, then it is converted to byte data type. The result is expr modulo 256.
 
note
Use BYTSCL to convert expr to byte data type using scaling rather than modulo.
If the values of expr are within the range of a long integer, but outside the range of a byte (0 to +255), a misleading result occurs without an accompanying message. For example, BYTE(256)erroneously results in 0. If the values of expr are outside the range of a long integer data type, an error message may be displayed.
In addition, PV-WAVE does not check for overflow during conversion to byte data type. The values in expr are simply converted to long integers and the low 8 bits are extracted.
Example 1
a = BYTE('01abc')
INFO, a
; PV-WAVE prints: A   BYTE = Array(5)
PRINT, a
; PV-WAVE prints: 48   49   97   98   99
Example 2
a = BYTE(1.2)
PRINT, a
; PV-WAVE prints: 1 
Example 3
a = BYTE(-1)
PRINT, a
; PV-WAVE prints: 255
The calculated result is 255 (bytes are modulo 256).
See Also
BINDGEN,   BYTARR,   BYTEORDER,   BYTSCLCOMPLEXDOUBLEFIXFLOAT, INT32,  LONG, alibByte
For more information on using this function to extract data, see the PV‑WAVE Programmer’s Guide.

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.