How To Convert String To Int Pascal

Table of contents:

How To Convert String To Int Pascal
How To Convert String To Int Pascal

Video: How To Convert String To Int Pascal

Video: How To Convert String To Int Pascal
Video: String To Int in Java - Learn How to Convert a String to an Integer 2024, May
Anonim

Pascal is one of the basic programming languages, developed in 1970 by Swiss scientist Niklaus Wirth. It is very popular in educational institutions due to its simplicity and great functionality.

How to convert string to int pascal
How to convert string to int pascal

Data types

In the programming language "Pascal" there are several types of data, knowledge of the features of which is necessary for writing programs. There are only five main data types:

  • Integer data is an integer that is 1 to 4 bytes long and has a specific range depending on the subtype:

    • Short - from -128 to 127
    • Byte - from 0 to 255
    • Word - 0 to 65535
    • Int - from -32 768 to 32 767
    • Long - from -2 147 483 648 to 2 147 483 647
  • Real data is a floating point number with a huge range. There are five subtypes of this type of data in total:

    • Real - from 2.9 E-39 to 1.7 E +38
    • Single - from 1.5 E-45 to 3.4 E + 38
    • Double - from 5.0 E-324 to 1.7 E + 308
    • Extended - from 3.4E-4951 to 1.1E + 4932
    • Comp - from -2 E + 63 to +2 E + 63 -1
  • Character data - any character of the alphabet. In languages it is denoted by the abbreviation "char", has no subtypes.
  • String data is a sequence of characters written as "string".
  • Boolean data - represented as true or false.

Translations of one type of data into another

Sometimes it becomes necessary to work simultaneously with several types of information. For example, if you write the expression "45 + 45" in the "int" type, then when performing work, the program will display the sum of these numbers. The situation is different with a string variable. When writing the same expression, either the number "4545" or the expression itself will appear on the screen, depending on the placement of quotation marks. Mathematical operations can only be performed using integer or real data types, since only they operate on numbers.

For example, let's find the sum of 2 and 3 using the Pascal programming language.

Image
Image

Since the integer data type is used, when the program starts, only the result of the sum of two numbers is displayed. If there is a need to format the answer beautifully, then you should use string data. This can be done in one line or in two. The first method is the simplest, since it does not require translation from "int" to "string".

Image
Image

Two lines appear on the screen. The first line indicates what operation was performed, and the second displays its result. This is one way you can use several kinds of data. However, with its help it will not be possible to properly format the text if you need to write several expressions. To solve this problem, you need to enter variables and use them to convert numeric data to strings.

Image
Image

Thus, we get two expressions, each of which is written on one line. This use of translating variables of type "string" into variables of type "int" is one of the most common and is used constantly. Other data types can be changed in the same way.

Recommended: