# Integer Is One Of The Data Types In Programming, Let’s Meet Together!

Integer is – In the world of programming, data is an important part that cannot be forgotten or omitted. The reason is, programming will always be related to the activities of processing data into the information needed.

So, in order to keep the data consistent and use computer memory more efficiently, a programmer must be familiar with the various types of data used when working.

Because the data type will help the computer to interpret the value of a variable correctly so that errors are avoided. One type of data that is often used by programmers is integer or integer data.

In this article, we will discuss this integer data type in full to help those of you who are new to programming. So without further ado, let’s begin!

## Integers Is

Strictly speaking, a computer program is a collection of pieces of data that are manipulated in various ways. “Data” here is of various types, some are in the form of numbers such as positive and negative numbers, integers, fractional numbers, small numbers, large numbers, and so on. There is also data in the form of characters, such as names, addresses, and others.

When a programmer works, he must determine the type of information to be used. For example, when creating a program to determine the distance from Indonesia to South Korea, what kind of data is needed so that the information is clear.

Well, an integer is an integer data type, both positive and negative, with a certain range . In other words, in integer data there are no letters or decimal numbers. Examples of integer data are 1, 59, 899, -20, and so on.

FYI, to use negative numbers, just add a minus sign (-) in front of the number. Then, for numbers whose value is thousands, tens of thousands, or more, they cannot be written with a separator (both full stop and comma). For example, to write one thousand five hundred, just write 1500 instead of 1500 or 1500.

## Integer Data Value And Representation

Because it doesn’t recognize letters and decimal numbers, you could say the value of integer data is an integer like you find in Mathematics. Representation here refers to the manner or method of storing the value in computer memory.

Thus, integer data is divided into two categories, namely signed and unsigned. Signed integers represent negative integer values ​​(-1, -10, and so on) while unsigned integers represent positive integers (1, 10, and so on).

Then the representation of unsigned integers in the computer is a string of bits that uses a binary number system with varying orders, some are in the form of Big Endian, some are in the form of Little Endian.

Oh yes, apart from width, size, or precision, integer data also has other variations depending on the number of bits represented by it. For an integer that has n bits it can encode 2n and if the data type is an unsigned integer then the range is from 0 to 2n – 1.

Usually, a programmer has his own considerations for using the integer data type, for example like:

• The amount of memory that can be used by the variable
• The largest and the smallest number that can be stored in a variable
• Whether the variable handles positive, negative, or only positive (unsigned) storage
• And others

## Types of Integers in Several Programming Languages

• ### C language

In the C programming language, integer data types are divided into four types, namely byte, short, int, and long which have their own characteristics. The following is a brief explanation for the four types of integer data types:

#### Bytes

The integer byte type is generally used when programmers work with data streams on networks or files. Its function is to carry out processes such as writing or reading data.

In addition, it can also be used when programmers use binary data that is not supported by other types of the Java programming language.

An example of a byte integer data type:

public class Main {
public static void main(String [] args)
//Variable declaration
byte value = 1;
//Output
System.out.println(“Value of bytes = ” + value);
}

#### short

The short type is generally used on computers with a 16-bit capacity, that’s why this type is quite difficult to find nowadays because both laptops and 16-bit computers are becoming rare.

Short integer data type example

public class Main {
public static void main(String[] args)
//Variable declaration
short value = 2;
//result
System.out.println(“Value of short = ” + value);
}

#### int

The int type is the most used type today because it represents numbers in programming. In addition, the int type is also considered more efficient than other integer data types.

Int integer data type example
public class Main {
public static void main(String[] args)
//Variable declaration
int value = 20;
//result
System.out.println(“Value of int = ” + value);
}

In theory, any expression that includes a byte, short, and long type, must pass an int procedure to be promoted before entering the calculation process. For example like this:

public class Main {
public static void main (String []args)
//Creates a variable of some data type
byte value = 1;
short anotherValue = 2;
int results = 3;
int anotherResult;
//Sum byte, short, and int variables
anotherResult = value + anotherValue + result;
//Prints the result
System.out.println(“Value of result = ” + anotherResult);
}

#### Long

The last integer data type is more often used when the data value used is more than the capacity range of type int, byte, or short. The reason is because the long type does have the widest range compared to the other types.

Integer data type example long
public class Main {
public static void main (String [] args)
//
long value variable declaration = 22121;
//result
System.out.println(“Value of long = ” + value);
}

All data types above can store negative integers and positive integers. For storing positive and zero integers, you can use the keyword “unsigned” in front of the data type, for example:

• unsigned short in, 2 bytes, range 0 to 60,000
• unsigned int, 4 bytes, range 0 to 4,294,900,290

In addition, below is a table that contains the different ranges of each integer data type:

 Data Type Size (Bit) Range Bytes 8 -128 to 127 short 16 -32768 to 32767 int 32 -2147483648 to 2147483647 Long 64 -9223372036854775808 to 9223372036854775807

The range of each data type above is related to the memory capacity needed to store that number. So the greater the range , the greater the required memory capacity.

• ### Pascal language

In the Pascal programming language, the integer data type can hold 16-bit data, however, because integer itself is a signed data type, it can only be assigned values ​​from -215 to 215-1 or -32768 to 32767. Why is that? ? Because 1 bit is used as a marker for positive or negative.

• ### C# language

In the C# programming language there are several types of integer data types that can be used, namely:

#### Bytes

An unsigned integer with size 8-bit. The same as the System Byte data type in the Microsoft NET Framework.

#### Sbyte:

A signed integer with the same 8-bit size as the System Sybte data type in the Microsoft NET Framework.

#### short

A signed integer with the same 16-bit size as the System Int16 data type in the Microsoft NET Framework.

#### Ushort:

An unsigned integer with the same 16-bit size as the System UInt16 data type in the Microsoft NET Framework.

#### int

A signed integer with the same 32-bit size as the System Int32 data type in the Microsoft NET Framework.

#### Uint

An unsigned integer that has a 32-bit size and is the same as the System UInt32 data type in the Microsoft NET Framework.

#### Long

A signed integer that has a 64-bit size and is the same as the System Int64 data type in the Microsoft NET Framework.

Ulong
An unsigned integer that has the same 64-bit size as the System UInt64 data type in the Microsoft NET Framework.

To make it easier to distinguish integer data type names in the C# programming language and the Microsoft NET Framework, you can see the comparison in the image below:

• ### PHP language

Integer data types can also be found in the PHP programming language which is commonly used to write integer data, such as 25, 100, 300, or others. Integers in PHP can also be positive or negative numbers.

An example of an integer data type in PHP:
<?php
//an example of an integer in PHP
\$sale_price=120000;
\$item_amount=100;
\$shipping_cost=500000;

echo \$selling_price;
echo “<br />”;
echo \$item_amount;
echo “<br /”;
echo \$shipping_cost;
?>

In the PHP programming language, integer data types can also be combined with mathematical operations, such as multiplication, addition, division, or subtraction. For example:

<?php
\$a=10;
\$b=5;
\$c= \$a + \$b;

echo “result is \$c”
echo “<hr>;
?>

## How to Write Integer Data Type in C Programming Language

To be able to learn to write integer data types, Sinaumed’s must first understand what is called a variable. Because the two are related to each other, where the variable is a place to store a value and the data type is the type of value that can be stored in the variable.

For example, in math class you often meet x and y, right? Now, “x” and “y” are called variables because they are places to store a value. For example x = 3 and y = 4.

In comparison, variables are the same as containers and data types are the objects that will be stored in the container.

First, write down the data type first, then write down the variable name and the contents of the data. For example, you want to create a weight variable with an integer (int) data type in the form of the number 59, then the writing becomes:

int weight = 59;

Remember, every time you create a variable it must end with a semicolon (;). In addition, you should immediately fill in the data values ​​that you want to store like the example above.

After that, remember carefully the rules for writing variables in the C programming language, which consist of:

• Variable names cannot begin with a number or symbol
• Variable names may not use keywords that already exist in the C programming language such as void, int, if, or something else
• Variable names are case sensitive, meaning uppercase and lowercase letters are very different. For example the address variable with Address are two different variables.
• Use an underscore (_) to write a variable name consisting of two or more words, such as home_address, cellphone_number, or something else.

## Example Program With Integer Data Type

After learning to write the integer data type, next we will try to make a program with the integer data type. To make it easier, you should first download the Codeblocks software.

If the Codeblocks software is already installed on your laptop, then open the software and create a new program with the name data_integer, then write the code below:

#include <stdio.h>
int main(void)
{
int number3;

number3 = 2147483647;

printf(“Enter number3(int): %d\n”,number3);

returns 0;
}

After that, run the program code, the result will be like this:

Sinaumed’s can also write code that combines all four types of integer data types in the C programming language, from char, short, int, and long. You do this by creating a new variable for each type of data type, for example:

#include <stdio.h>
int main(void)
{
first char;
second short;
third int;
fourth long;

first = 10;
second = 100;
third = 1000;
fourth = 10000;

printf(“Enter the first variable (char): %d\n”, first);
printf(“Enter the second (short) variable %d\n”, second);
printf(“Enter the third variable (int): %d\n”, third);
printf(“Enter the fourth variable (long): %d\n”, fourth);

printf(“\n”);
returns 0;
}

When this program code is executed, the output will be like this:

After defining each variable, then proceed with filling in the variables using numbers. The numbers are free as long as they do not exceed the maximum value each data value can hold.

In the example above, we use the numbers 10 for the first variable, 100 for the second variable, 1000 for the third variable, and 10000 for the fourth variable. Then each variable is displayed with the printif command.

Then, what happens if we try to enter a value that is outside the maximum limit that can be accommodated by each type of data? Let’s try it right away:

#include <stdio. h>

int main(void)
{
first unsigned char;
second unsigned short;
third unsigned int;
fourth unsigned long;

first = 299;
second = 65599;
third = 4294967299;
fourth = 4294967299;

printf(“Enter the first variable (char): %d\n”, number1);
printf(“Enter the second variable (short) %d\n”, number2);
printf(“Enter the third variable (int): %u\n”, number3);
printf(“Enter the fourth variable (long): %u\n”, number4);

printf(“\n”);
returns 0;
}

After running, the results that appear are as follows:

From the discussion above, it can be said that an integer is a positive or negative integer data type with a certain range . Thus the discussion about integers. Hopefully all the discussion above is useful and can add to your insight. If you want to find books about coding, then you can get them at sinaumedia.com .

To support Sinaumed’s in adding insight, sinaumedia always provides quality and original books so that Sinaumed’s has #MoreWithReading information.

Author: Gilang Oktaviana Putra

Source: