Script – IDEC High Performance Series User Manual
Page 993
![background image](/manuals/350385/993/background.png)
WindO/I-NV2 User’s Manual
20-29
5 Script Coding Examples
20
Script
Script
Operation description
This example converts a decimal value to octal using a while statement.
By repeating the process to divide the original decimal data by 8 and converting each digit to octal in a while
statement, the conversion is implemented up to four digits.
The unconverted decimal value is stored in LDR100. After the script is executed, the converted octal value is stored in
LDR200.
■
Example 5.1.10 Decimal to octal conversion using a while statement
// Convert a decimal value to octal
// - For example, convert 10 (dec) to 12 (oct), 16 (dec) to 20 (oct)
// - Convert a value to octal up to 4 digits max
@1 = 0;
// while counter
@2 = [LDR 100];
// gets original data
@3 = 1;
// decimal base
@4 = 0;
// calculation results
// repeat four times
while (@1 < 4)
{
// Extract 1st octal digit from original data. Store working result in @10.
@10 = @2 % 8;
// Convert the extracted results to decimal and add to results
@4 = @4 + (@10 * @3);
// Increase the decimal base by one digit
@3 = @3 * 10;
// Reduce the original data by one digit
@2 = @2 / 8;
// If @2 is 0, terminate the while statement
if (0 == @2)
{
break;
}
// Increment while counter by 1
@1 = @1 + 1;
}
// Store the calculation result in LDR200
[LDR 200] = @4;