V+ Language Reference Guide, v17.x


INTB real-valued function

Syntax

INTB ($string, first_char)

Function

Return the value of two bytes of a string interpreted as a signed 16-bit binary integer.

Parameters

$string

String expression that contains the two bytes to be converted.

first_char

Optional real-valued expression that specifies the position of the first of the two bytes in the string.

If first_char is omitted or has a value of 0 or 1, the first two bytes of the string are extracted. If first_char is greater than 1, it is interpreted as the character position for the first byte. For example, a value of 2 means that the second byte contains bits 9 to 16 and the third byte contains bits 1 to 8. An error is generated if first_char specifies a byte pair that is beyond the end of the input string.

Details

Two sequential bytes of a string are interpreted as being a 2's-complement 16-bit signed binary integer. The first byte contains bits 9 to 16, and the second byte contains bits 1 to 8.

The main use of this function is to convert binary numbers from an input data record to values that can be used internally by V+.

The expression

value = INTB($string, first_char)

is equivalent to the following instruction sequence:

value = ASC($string,first_char)*256 + ASC($string,first_char+1)
IF value > 32767 THEN 	
    value = value-65536 	
END

To compute an unsigned integer, use: INTB($string) BAND ^HFFFF.

Examples

INTB($CHR(10)+$CHR(5))           ;Returns the value 2565
INTB($CHR(255)+$CHR(255))        ;Returns the value -1

Related Keywords

ASC real-valued function

DBLB real-valued function

FLTB real-valued function

$INTB string function

LNGB real-valued function

VAL real-valued function


Submit comments to: techpubs@adept.com
Last modified on: 3/27/2012
Copyright © 1994 - 2012. Adept Technology, Inc.