Conversions Library
mikroPascal PRO for FT90x 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
- Uint64ToStr
- Int64ToStr
- FloatToStr
- ExtendedToStr
- ByteToStrWithZeros
- ShortToStrWithZeros
- WordToStrWithZeros
- IntToStrWithZeros
- LongWordToStrWithZeros
- LongIntToStrWithZeros
- Uint64ToStrWithZeros
- Int64ToStrWithZeros
- ByteToHex
- ShortToHex
- WordToHex
- IntToHex
- LongWordToHex
- LongIntToHex
- Uint64ToHex
- Int64ToHex
- 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); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : byte; txt : array[3] of char; ... t := 24; ByteToStr(t, txt); // txt is " 24" (one blank here) |
Notes |
None. |
ShortToStr
Prototype |
procedure ShortToStr(input : short; var output : array[4] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : short; txt : array[4] of char; ... t := -24; ShortToStr(t, txt); // txt is " -24" (one blank here) |
Notes |
None. |
WordToStr
Prototype |
procedure WordToStr(input : word; var output : array[5] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : word; txt : array[5] of char; ... t := 437; WordToStr(t, txt); // txt is " 437" (two blanks here) |
Notes |
None. |
IntToStr
Prototype |
procedure IntToStr(input : integer; var output : array[6] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : integer; txt : array[6] of char; //... begin input := -4220; IntToStr(input, txt); // txt is ' -4220' |
Notes |
None. |
LongintToStr
Prototype |
procedure LongintToStr(input : longint; var output : array[11] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : longint; txt : array[11] of char; //... begin input := -12345678; LongintToStr(input, txt); // txt is ' -12345678' |
Notes |
None. |
LongWordToStr
Prototype |
procedure LongWordToStr(input : dword; var output : array[10] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : longint; txt : array[10] of char; //... begin input := 12345678; LongWordToStr(input, txt); // txt is ' 12345678' |
Notes |
None. |
Uint64ToStr
Prototype |
procedure Uint64ToStr(input : uint64; var output : array[20] of char); |
---|---|
Description |
Converts input uint64 number to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : uint64; txt : array[20] of char; //... begin input := 0x1122334455667788; Uint64ToStr(input, txt); // txt is ' 1122334455667788' |
Notes |
None. |
Int64ToStr
Prototype |
procedure Int64ToStr(input : int64; var output : array[20] of char); |
---|---|
Description |
Converts input int64 number to a string. The output string is right justified and the remaining positions on the left (if any) are filled with blanks. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : int64; txt : array[20] of char; //... begin input := 0x1122334455667788; Int64ToStr(input, txt); // txt is ' 1122334455667788' |
Notes |
None. |
FloatToStr
Prototype |
procedure FloatToStr(fnum : real; var str : array[23] of char); |
---|---|
Description |
Converts a floating point number to a string. The output string is left justified and null terminated after the last digit. |
Parameters |
|
Returns |
Nothing. |
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" |
Notes |
Given floating point number will be truncated to 7 most significant digits before conversion. |
ExtendedToStr
Prototype |
procedure ExtendedToStr(input : extended; var output : array[23] of char); |
---|---|
Description |
Converts a extended floating point number to a string. The output string is left justified and null terminated after the last digit. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var ff1, ff2, ff3 : extended; txt : array[23] of char; ... ff1 := -374.2; ff2 := 123.456789; ff3 := 0.000001234; ExtendedToStr(ff1, txt); // txt is "-374.20001" ExtendedToStr(ff2, txt); // txt is "123.45678" ExtendedToStr(ff3, txt); // txt is "0.000000" |
Notes |
None. |
ByteToStrWithZeros
Prototype |
procedure ByteToStrWithZeros(input: byte; var output: array[3] of char); |
---|---|
Description |
Converts input byte to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : byte; txt : array[3] of char; //... t := 37; ByteToStrWithZeros(t, txt); // txt is '0037' |
Notes |
None. |
ShortToStrWithZeros
Prototype |
procedure ShortToStrWithZeros(input: short; var output: array[4] of char); |
---|---|
Description |
Converts input short to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : byte; txt : array[4] of char; //... t := -37; ShortToStrWithZeros(t, txt); // txt is '-037' |
Notes |
None. |
WordToStrWithZeros
Prototype |
procedure WordToStrWithZeros(input: word; var output: array[5] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : word; txt : array[5] of char; //... t := 437; WordToStrWithZeros(t, txt); // txt is '00437' |
Notes |
None. |
IntToStrWithZeros
Prototype |
procedure IntToStrWithZeros(input: integer; var output: array[6] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : integer; txt : array[6] of char; //... t := -3276; IntToStrWithZeros(t, txt); // txt is '-03276' |
Notes |
None. |
LongWordToStrWithZeros
Prototype |
procedure LongWordToStrWithZeros(input: dword; var output: array[10] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : dword; txt : array[10] of char; //... t := 12345678; LongWordToStrWithZeros(t, txt); // txt is '0012345678' |
Notes |
None. |
LongIntToStrWithZeros
Prototype |
procedure LongIntToStrWithZeros(input: longint; var output: array[11] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : longint; txt : array[11] of char; //... t := -12345678; LongIntToStrWithZeros(t, txt); // txt is '-0012345678' |
Notes |
None. |
Uint64ToStrWithZeros
Prototype |
procedure Uint64ToStrWithZeros(input: uint64; var output: array[20] of char); |
---|---|
Description |
Converts input uint64 to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : uint64; txt : array[20] of char; //... t := 1234567890; Uint64ToStrWithZeros(t, txt); // txt is '00000000001234567890' |
Notes |
None. |
Int64ToStrWithZeros
Prototype |
procedure Int64ToStrWithZeros(input: int64; var output: array[20] of char); |
---|---|
Description |
Converts input int64 to a string. The output string is right justified and the remaining positions on the left (if any) are filled with zeros. |
Parameters |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : iint64; txt : array[20] of char; //... t := -1234567890; Int64ToStrWithZeros(t, txt); // txt is '-0000000001234567890' |
Notes |
None. |
ByteToHex
Prototype |
procedure ByteToHex(input : byte; var output : array[2] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : byte; txt : array[2] of char; ... t := 2; ByteToHex(t, txt); // txt is "02" |
Notes |
None. |
ShortToHex
Prototype |
procedure ShortToHex(input : short; var output : array[2] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : short; txt : array[2] of char; ... t := -100; ShortToHex(t, txt); // txt is "9C" |
Notes |
None. |
WordToHex
Prototype |
procedure WordToHex(input : word; var output : array[4] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var t : word; txt : array[4] of char; ... t := 1111; WordToHex(t, txt); // txt is "0457" |
Notes |
None. |
IntToHex
Prototype |
procedure IntToHex(input : integer; var output : array[64] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : integer; txt : string[4]; //... input := -32768; IntToHex(input, txt); // txt is '8000' |
Notes |
None. |
LongWordToHex
Prototype |
procedure LongWordToHex(input : dword; var output : array[8] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : dword; txt : array[8] of char; //... input := 65535; LongWordToHex(input, txt); // txt is '0000FFFF' |
Notes |
None. |
LongIntToHex
Prototype |
procedure LongIntToHex(input : longint; var output : array[8] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : longint; txt : array[8] of char; //... input := -2147483648; LongIntToHex(input, txt); // txt is '80000000' |
Notes |
None. |
Uint64ToHex
Prototype |
procedure Uint64ToHex(input : uint64; var output : array[16] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : uint64; txt : array[16] of char; //... input := 4294967295; Uint64ToHex(input, txt); // txt is '00000000FFFFFFFF' |
Notes |
None. |
Int64ToHex
Prototype |
procedure Int64ToHex(input : int64; var output : array[16] of char); |
---|---|
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 |
|
Returns |
Nothing. |
Requires |
Nothing. |
Example |
var input : int64; txt : array[16] of char; //... input := -4294967295; Int64ToHex(input, txt); // txt is '-0000000FFFFFFFF' |
Notes |
None. |
StrToInt
Prototype |
function StrToInt(var input: string[6]): integer; |
---|---|
Description |
Converts a string to an integer. |
Parameters |
|
Returns |
Integer variable. |
Requires |
Input string is assumed to be the correct representation of a number. The conversion will end with the first character which is not a decimal digit. |
Example |
var ii: integer; begin ii:= StrToInt('-1234'); end. |
Notes |
None. |
StrToWord
Prototype |
function StrToWord(var input: string[5]): word; |
---|---|
Description |
Converts a string to word. |
Parameters |
|
Returns |
Word variable. |
Requires |
Input string is assumed to be the correct representation of a number. The conversion will end with the first character which is not a decimal digit. |
Example |
var ww: word; begin ww:= StrToword('65432'); end. |
Notes |
None. |
Bcd2Dec
Prototype |
function Bcd2Dec(bcdnum : byte) : byte; |
---|---|
Description |
Converts input BCD number to its appropriate decimal representation. |
Parameters |
|
Returns |
Converted decimal value. |
Requires |
Nothing. |
Example |
var a, b : byte; ... a := 22; b := Bcd2Dec(a); // b equals 34 |
Notes |
None. |
Dec2Bcd
Prototype |
function Dec2Bcd(decnum : byte) : byte; |
---|---|
Description |
Converts input number to its appropriate BCD representation. |
Parameters |
|
Returns |
Converted BCD value. |
Requires |
Nothing. |
Example |
var a, b : byte; ... a := 22; b := Dec2Bcd(a); // b equals 34 |
Notes |
None. |
Bcd2Dec16
Prototype |
function Bcd2Dec16(bcdnum : word) : word; |
---|---|
Description |
Converts 16-bit BCD numeral to its decimal equivalent. |
Parameters |
|
Returns |
Converted decimal value. |
Requires |
Nothing. |
Example |
var a, b : word; ... a := 0x1234; // a equals 4660 b := Bcd2Dec16(a); // b equals 1234 |
Notes |
None. |
Dec2Bcd16
Prototype |
function Dec2Bcd16(decnum : word) : word; |
---|---|
Description |
Converts decimal value to its BCD equivalent. |
Parameters |
|
Returns |
Converted BCD value. |
Requires |
Nothing. |
Example |
var a, b : word; ... a := 2345; b := Dec2Bcd16(a); // b equals 9029 |
Notes |
None. |
What do you think about this topic ? Send us feedback!