我必须创建一个具有如下输出的程序:
def var vbit as logical extent 64 initial "false".
def var x as char form "x(16)" /* to store the decimal input */
Input : 2220010000000000
convert the value into:
22=00100010
20=00100000
01=00000001
00=00000000
00=00000000
00=00000000
00=00000000
然后如果二进制文件已排序,则输出为:
123456789012345678901234
00100010001000000000000100000000000000000000000000000000
从这个二进制文件中,改变图像上的vbit [x]。
非常感谢你的回答。
答案 0 :(得分:1)
这是一个简单的例子,很可能不适用于环境......
据我所知,没有内置函数或方法来创建二进制数。所以我从这里借了一个函数: http://knowledgebase.progress.com/articles/Article/P125416
我已修改函数以返回4位格式的整数,这适用于此特定示例,但当然不适用于较大的二进制数。
DEFINE VARIABLE vbit AS LOGICAL EXTENT 64 NO-UNDO .
DEFINE VARIABLE cString AS CHARACTER NO-UNDO FORMAT "x(16)".
DEFINE VARIABLE cBinary AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
ASSIGN
cString = "2220010000000000".
FUNCTION getBinary RETURNS CHARACTER (INPUT piValue AS INTEGER):
DEFINE VARIABLE cReturn AS CHARACTER NO-UNDO .
DEFINE VARIABLE iReturn AS INTEGER NO-UNDO FORMAT "9999".
DO WHILE piValue > 0:
ASSIGN
cReturn = STRING( piValue MOD 2 ) + cReturn
piValue = TRUNCATE( piValue / 2, 0 )
.
END.
IF cReturn = "" THEN cReturn = "0".
iReturn = INTEGER(cReturn).
RETURN STRING(iReturn, "9999").
END FUNCTION.
/* Convert the string of integers into a binary format */
DO i = 1 TO LENGTH(cString):
cBinary = cBinary + getBinary(INTEGER(SUBSTRING(cString, i, 1))).
END.
/* Move the binary numbers into the boolean variable */
DO i = 1 TO LENGTH(cBinary).
IF SUBSTRING(cBinary, i, 1) = "1" THEN
vbit[i] = TRUE.
ELSE
vbit[i] = FALSE.
END.
/* Uncomment this to output
123456789012345678901234
00100010001000000000000100000000000000000000000000000000
*/
/*
DISP "123456789012345678901234" SKIP
cBinary FORMAT "x(70)" WITH FRAME fr1 4 DOWN WIDTH 90.
*/
/* Display the boolean variable in the specified format */
DISP vbit WITH FRAME fr2 SIDE-LABELS 4 COLUMNS WIDTH 90 25 DOWN.