Facebook Pixel

AN-00196 Designer or ViSi 4DGL Strings Print Formats – the Long Decimal Format Specifiers

Description

There are four decimal format specifiers:

    • "%d",for signed decimal
    • "%u",for unsigned decimal
    • "%ld",for long signed decimal
    • "%lu",for long unsigned decimal

This application note discusses how the long signed decimaland long unsigned decimal format specifiers are used with the str_Printf(…) function. This application note is intended for use in the Workshop 4 – Designer environment. The 4DGL code of the Designer project can be copied and pasted to an empty ViSi project and it will compile normally. The code can also be integrated to that of an existing ViSi project.

Supported Processor PICASO, DIABLO16
Supported Environment Designer, ViSi
Difficulty Medium

File Downloads
Files
 

Description

There are four decimal format specifiers:

This application note discusses how the long signed decimal and long unsigned decimal format specifiers are used with the str_Printf(…) function. This application note is intended for use in the Workshop 4 – Designer environment. The 4DGL code of the Designer project can be copied and pasted to an empty ViSi project and it will compile normally. The code can also be integrated to that of an existing ViSi project.

Before getting started, the following are required:

  • Any of the following 4D Picaso display modules:

        gen4-uLCD-24PT

        gen4-uLCD-28PT

        gen4-uLCD-32PT

        uLCD-24PTU

        uLCD-28PTU

        uVGA-III 

and other superseded modules which support the Designer and/ or ViSi environments.

  • The target module can also be a Diablo16 display

        gen4-uLCD-24D Series

        gen4-uLCD-28D Series

        gen4-uLCD-32D Series

        gen4-uLCD-35D Series

        gen4-uLCD-43D Series

        gen4-uLCD-50D Series

        gen4-uLCD-70D Series

        uLCD-35DT

        uLCD-43D Series

        uLCD-70DT

Visit www.4dsystems.com.au/products to see the latest display module products that use the Diablo16 processor.

for non-gen4 displays (uLCD-xxx)

for gen-4 displays (gen4-uLCD-xxx)

  • micro-SD (µSD) memory card
  • Workshop 4 IDE (installed according to the installation document)
  • When downloading an application note, a list of recommended application notes is shown. It is assumed that the user has read or has a working knowledge of the topics presented in these recommended application notes.

 

Application Overview

The application note Designer or ViSi Strings and Character Arrays explains how 4DGL strings and character arrays are stored in and accessed from memory. It also differentiates between word-aligned and byte-aligned pointers. Furthermore, it introduces the use of the function str_Printf(…).

The application note Designer or ViSi 4DGL Strings Print Formats – the String and Character Format Specifiers shows how the string and character format specifiers (“%s” and “%c”, respectively) are used. Also, it covers the topics “Automatic Advancing of the Pointer” and “Dynamic Construction of the Format Specifier”.

This application note now further explains the use of the str_Printf(…) function together with the long signed decimal and long unsigned decimal format specifiers.

 

Setup Procedure

For instructions on how to launch Workshop 4, how to open a Designer project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

Designer Getting Started - First Project

For instructions on how to launch Workshop 4, how to open a ViSi project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

 

Create a New Project

For instructions on how to create a new Designer project, please refer to the section “Create a New Project” of the application note

Designer Getting Started - First Project

For instructions on how to create a new ViSi project, please refer to the section “Create a New Project” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

 

Design the Project

The Format Specifier “%ld”

The format specifier “%ld” is used for displaying long signed decimal numbers. A long signed decimal in 4DGL is a signed 32-bit (or 4-byte) integer value, the range of which is from -2,147,483,648 to 2,147,483,647 (-231 to 231-1). Consider the code snippet shown below.

The output of the above code is:

The function umul_1616(…) performs an unsigned multiplication of two 16-bit values, placing the 32-bit result in a two-word array. In this example, the two 16-bit values are 500 and 2000. When multiplied together the product of these is 1000000. If we print the contents of the word array val32 in hexadecimal format,

 

we get,

We analyse the contents of the word array val32.

Note also that the pointer was advanced by four bytes after the long signed decimal value was printed.

Therefore, the long signed decimal format specifier, “%ld”, causes the str_Printf(…) function to get four bytes from the address starting at that pointed to by the byte-aligned pointer. str_Printf(…) then treats these four bytes as a 32-bit signed integer and prints the decimal equivalent.

The 32-bit data found starting at address 16, in this example, is “0x000F 4240”, the decimal equivalent of which is “1000000”.

The Width and Zero Flag Sub-specifiers

The Width Sub-specifier

Consider the output below.

The code for the first line is

The code for the second line is

Note that in the second line, the number has three spaces preceding it. This is because the width specifier was used in the str_Printf(…) function.

 

Here the width specifier value is 10, so the field width of the printed figure is ten digits, and since the number is only seven digits, it is preceded by three space characters.

The Zero Flag Sub-specifier

Suppose we want the number to be preceded with zeros rather than spaces, we would write,

Here the width sub-specifier is preceded by the zero flag sub-specifier, which would cause the number to be left-padded with zeros instead of spaces. To illustrate,

Therefore, without the zero flag sub-specifier, the default character with which a number, printed with a certain field width, is to be left-padded is the space character.  The width and zero flag sub-specifiers can be used with other format specifiers besides the long signed decimal format specifier.

The Designer project for the discussions on the long signed decimal format specifier and the width and zero flag sub-speficiers is “stringsBasics6.4dg” (attached).

Printing Negative Numbers

Print a Negative Long Decimal Number

To print a negative long decimal number, we first generate a negative 32-bit integer by multiplying the two 16-bit integers shown below.

 

Again, the function umul_1616(…) performs an unsigned multiplication of two 16-bit values placing the 32-bit result in a two-word array. In this example, the two 16-bit values are 0xFF12 and 0xFF34. When treated as unsigned numbers and multiplied together, the product of these is 0xFE46 BDA8. If we print the contents of the word array val32 in hexadecimal format,

we get,

Using the long signed decimal format specifier, “%ld”, would cause str_Printf(…) to treat the two-word data as a signed 32-bit integer. Hence, we get the decimal equivalent value of “-28918360” for “0xFE46 BDA8”.

Print a Long Unsigned Decimal Number

To make str_Printf(…) treat the data inside val32[0] and val32[1] as an unsigned 32-bit integer, we use the long unsigned decimal format specifier “%lu”.

Hence we get the equivalent decimal value “4266048936”.

Dynamic Construction of the Format Specifier

As was shown in the application note Designer or ViSi 4DGL Strings Print Formats – the String and Character Format Specifiers, the format specifier argument of the str_Printf(…) function can also be a word-aligned string pointer, allowing dynamic construction of the printing format. We will now use dynamically constructed format specifiers, together with the width and zero flag sub-specifiers, to come up with the formatted display output shown below.

The code snippet for the above output is:

The Designer project for the remaining part of this application note is “stringsBasics7b.4dg” (attached). Although the examples are simple, the ability to construct a format specifier dynamically can be a powerful tool.

 

Run the Program

For instructions on how to save a Designer project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note

Designer Getting Started - First Project

For instructions on how to save a ViSi project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

The uLCD-32PTU and uLCD-35DT display modules are commonly used as examples, but the procedure is the same for other displays.

 

Share: