Conversions Library
mikroPascal PRO for PIC Conversions Library provides routines for numerals to strings and BCD/decimal conversions.
Library Dependency Tree
Library Routines
You can get text representation of numerical value by passing it to one of the following routines:
- ByteToStr
- ShortToStr
- WordToStr
- IntToStr
- LongIntToStr
- LongWordToStr
- FloatToStr
- WordToStrWithZeros
- IntToStrWithZeros
- LongWordToStrWithZeros
- LongIntToStrWithZeros
- ByteToHex
- ShortToHex
- WordToHex
- IntToHex
- LongWordToHex
- LongIntToHex
- StrToInt
- StrToWord
The following functions convert decimal values to BCD and vice versa:
ByteToStr
| Prototype |
procedure ByteToStr(input : byte; var output : array[3] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input byte to a string. The output string is right justified and remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : byte;
txt : array[3] of char;
...
t := 24;
ByteToStr(t, txt); // txt is " 24" (one blank here)
|
ShortToStr
| Prototype |
procedure ShortToStr(input : short; var output : array[4] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input short (signed byte) number to a string. The output string is right justified and remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : short;
txt : array[4] of char;
...
t := -24;
ShortToStr(t, txt); // txt is " -24" (one blank here)
|
WordToStr
| Prototype |
procedure WordToStr(input : word; var output : array[5] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input word to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : word;
txt : array[5] of char;
...
t := 437;
WordToStr(t, txt); // txt is " 437" (two blanks here)
|
IntToStr
| Prototype |
procedure IntToStr(input : integer; var output : array[6] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input integer number to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : integer;
txt : string[6];
//...
input := -4220;
IntToStr(input, txt); // txt is ' -4220'
|
LongintToStr
| Prototype |
procedure LongintToStr(input : longint; var output : array[11] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input longint number to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : longint;
txt : array[11] of char;
//...
input := -12345678;
LongIntToStr(input, txt); // txt is ' -12345678'
|
LongWordToStr
| Prototype |
procedure LongWordToStr(input : dword; var output : array[10] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input double word number to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : dword;
txt : array[10] of char;
//...
input := 12345678;
LongWordToStr(input, txt); // txt is ' 12345678'
|
FloatToStr
| Prototype |
procedure FloatToStr(input : real; var output : array[23] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts a floating point number to a string. Parameters :
The output string is left justified and null terminated after the last digit. Note :
Given floating point number will be truncated to 7 most significant digits before conversion.
|
| Requires |
Nothing. |
| Example |
var ff1, ff2, ff3 : real;
txt : array[10] of char;
...
ff1 := -374.2;
ff2 := 123.456789;
ff3 := 0.000001234;
FloatToStr(ff1, txt); // txt is "-374.20001"
FloatToStr(ff2, txt); // txt is "123.45678"
FloatToStr(ff3, txt); // txt is "0.000000"
|
WordToStrWithZeros
| Prototype |
procedure WordToStrWithZeros(input: word; var output: array[5] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input word to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : word;
txt : array[5] of char;
//...
t := 437;
WordToStrWithZeros(t, txt); // txt is '00437'
|
IntToStrWithZeros
| Prototype |
procedure IntToStrWithZeros(input: integer; var output: array[6] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input integer to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : integer;
txt : array[6] of char;
//...
t := -3276;
IntToStrWithZeros(t, txt); // txt is '-03276'
|
LongWordToStrWithZeros
| Prototype |
procedure LongWordToStrWithZeros(input: dword; var output: array[10] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input dword to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : dword;
txt : array[10] of char;
//...
t := 12345678;
LongWordToStrWithZeros(t, txt); // txt is '0012345678'
|
LongIntToStrWithZeros
| Prototype |
procedure LongIntToStrWithZeros(input: longint; var output: array[11] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input longint to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : longint;
txt : array[11] of char;
//...
t := -12345678;
LongIntToStrWithZeros(t, txt); // txt is '-0012345678'
|
ByteToHex
| Prototype |
procedure ByteToHex(input : byte; var output : array[2] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : byte;
txt : array[2] of char;
...
t := 2;
ByteToHex(t, txt); // txt is "02"
|
ShortToHex
| Prototype |
procedure ShortToHex(input : short; var output : array[2] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : short;
txt : array[2] of char;
...
t := -100;
ShortToHex(t, txt); // txt is "9C"
|
WordToHex
| Prototype |
procedure WordToHex(input : word; var output : array[4] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var t : word;
txt : array[4] of char;
...
t := 1111;
WordToHex(t, txt); // txt is "0457"
|
IntToHex
| Prototype |
procedure IntToHex(input : integer; var output : array[4] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : integer;
txt : string[4];
//...
input := -32768;
IntToHex(input, txt); // txt is '8000'
|
LongWordToHex
| Prototype |
procedure LongWordToHex(input : dword; var output : array[8] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : dword;
txt : array[8] of char;
//...
input := 65535;
LongWordToHex(input, txt); // txt is '0000FFFF'
|
LongIntToHex
| Prototype |
procedure LongIntToHex(input : longint; var output : array[8] of char); |
|---|---|
| Returns |
Nothing. |
| Description |
Converts input number to a string containing the number's hexadecimal representation. The output string is right justified and remaining positions on the left (if any) are filled with zeros. Parameters :
|
| Requires |
Nothing. |
| Example |
var input : longint;
txt : array[8] of char;
//...
input := -2147483648;
LongIntToHex(input, txt); // txt is '80000000'
|
StrToInt
| Prototype |
function StrToInt(var input: string[6]) : integer; |
|---|---|
| Returns |
Integer variable. |
| Description |
Converts a string to integer. |
| Requires |
The string is assumed to be a correct representation of a number. |
| Example |
var ii: integer;
...
ii := StrToInt('-1234');
|
StrToWord
| Prototype |
function StrToWord(var input: string[5]) : word; |
|---|---|
| Returns |
Word variable. |
| Description |
Converts a string to word. |
| Requires |
|
| Example |
var ww : word;
...
ww := StrToWord('65432');
|
Bcd2Dec
| Prototype |
function Bcd2Dec(bcdnum : byte) : byte; |
|---|---|
| Returns |
Converted decimal value. |
| Description |
Converts input BCD number to its appropriate decimal representation. Parameters :
|
| Requires |
Nothing. |
| Example |
var a, b : byte; ... a := 22; b := Bcd2Dec(a); // b equals 34 |
Dec2Bcd
| Prototype |
function Dec2Bcd(decnum : byte) : byte; |
|---|---|
| Returns |
Converted BCD value. |
| Description |
Converts input number to its appropriate BCD representation. Parameters :
|
| Requires |
Nothing. |
| Example |
var a, b : byte; ... a := 34; b := Dec2Bcd(a); // b equals 22 |
Bcd2Dec16
| Prototype |
function Bcd2Dec16(bcdnum : word) : word; |
|---|---|
| Returns |
Converted decimal value. |
| Description |
Converts 16-bit BCD numeral to its decimal equivalent. Parameters :
|
| Requires |
Nothing. |
| Example |
var a, b : word; ... a := 0x1234; // a equals 4660 b := Bcd2Dec16(a); // b equals 1234 |
Dec2Bcd16
| Prototype |
function Dec2Bcd16(decnum : word) : word; |
|---|---|
| Returns |
Converted BCD value. |
| Description |
Converts decimal value to its BCD equivalent. Parameters :
|
| Requires |
Nothing. |
| Example |
var a, b : word; ... a := 2345; b := Dec2Bcd16(a); // b equals 9029 |
What do you think about this topic ? Send us feedback!



Note :
Given floating point number will be truncated to 7 most significant digits before conversion.
