AN-00197 Designer or ViSi 4DGL Strings Print Formats – the Long Hexadecimal Format Specifier

Description

There are three hexadecimal format specifiers:

    • "%x", for hex byte
    • "%X", for hex word
    • "%lX", for hex long

This application note discusses how the long hexadecimal format specifier is 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 three hexadecimal format specifiers:

This application note discusses how the long hexadecimal format specifier is 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:

        uLCD-24PTU

        uLCD-28PTU

        uLCD-32PTU

        uLCD-32WPTU

        uLCD-43(P/PT/PCT)

        uVGA-III


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

  • The target module can also be a Diablo16 display

        uLCD-35DT

        uLCD-70DT

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

 

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 hexadecimal format specifier.

 

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 of the Project

The Format Specifier “%lX”

The format specifier “%lX” is used for displaying long hexadecimal numbers. A long hexadecimal in 4DGL is a 32-bit (or 4-byte) value, the range of which is from 0x0000 0000 to 0xFFFF FFFF (0  to 232-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 or 0xF4240. 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 hexadecimal value was printed.

Therefore, the long hexadecimal format specifier, “%lX”, 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 value and prints it in hexadecimal.

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 five 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 five hexadecimal digits wide, it is preceded by five 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 hexadecimal format specifier.

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

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 to come up with the formatted display output shown below, which is similar to that in the last example.

The code snippet for the above output can be implemented using dynamically constructed format specifiers, as shown below.

Where format is a word array declared at the start of the code.

The Designer project for the remaining part of this application note is “stringsBasics8b.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: