F$CVUI

From VSI OpenVMS Wiki
Jump to: navigation, search

F$CVUI() is a lexical function that extracts bit fields from character string data and converts the result to an unsigned number.

Syntax

F$CVUI(start-bit,number-of-bits,string)

Start-bit specifies the offset of the first bit to be extracted. The low-order (rightmost) bit of a string is position number 0.

If you specify an expression with a negative value, or with a value that exceeds the number of bits in the string, DCL displays the INVRANGE error message.

Examples

$ a = "a"
$ b = f$cvui(0,8,a)
$ show sym b
  B = 97   Hex = 00000061  Octal = 00000000141
 

In this example, symbol A stores an 8-bit value, which is 97 (the ASCII code for "a"). If we extract 8 bits from it into symbol B, 97 is extracted.

$ write sys$output f$cvui(0,f$integer(p1),p2)
$ count = 0
$loop:
$ if count .eq. f$integer(p1) then exit
$ write sys$output f$cvui(count,1,p2)
$ count = count + 1
$ goto loop
$ exit
 

This command procedure displays the value of P1 bits of string P2, then displays the bits one by one starting with the rightmost bit.