Basics of Data Types

What is data type?

The format of a variable or constant used in a program is known as data type. It is difficult to understand newbies. So, in this article, we are trying to give you a brief idea about the various data types we used in the industry. They are

  • Bit
  • Byte
  • Word
  • Double Integer
  • Real
  • Float
  • Signed Integer

Bit

The smallest piece of data that a computer can process and store is a bit (binary digit). Similar to an on/off light switch, a bit is always in one of two physical states. Usually a 0 or 1, the state is represented by a single binary integer. However, yes/no, on/off, or true/false can also be used to describe the state.

Capacitors are used to store bits in memory because they can store electrical charges. Each bit’s state, which in turn determines its value, is determined by the charge. Boolean is another name for the “bit.”

Byte

The sequence of 8 bits is called a byte. A byte is a data unit with eight bits (binary digits). Most computers use a byte to represent a character such as a letter, integer, or typographic sign. Each byte can store a string of bits that must be combined to form a larger unit for application purposes.

Unsigned indicates that the range only contains positive values. So, in a byte, an unsigned byte equals 0 to 256, while a signed byte equals -127 to 127.

A byte is often referred to as a small integer.

Word (Integer)

An integer is made up of 16 bits. The first start byte represents the LSB (least significant byte), while the last byte represents the MSB (most significant byte). 65536 is the value for 216. That means an integer can have 65536 different combinations of values.

A word is another name for an integer. However, a word cannot be signed. It will only be unsigned. Unsigned integers range from 0 to 65536, while signed integers range from -32767 to 32767. Word is an ordered set of characters that the computer treats as a unit. The length of the word can be fixed or changeable. The number of bits or characters in a word determines its length.

Word is a sequence of N bits where N = 16, 32, 64

Double Integer

Now, 32 bits add up to a double integer. The answer is 4294967296 for 232. That means a double integer can have 4294967296 different combinations or values. Unsigned double integers range from 0 to 4294967296, while signed double integers range from -2147483647 to 2147483647.

Two words in a PLC memory equal a double integer. Consider a Schneider PLC, for example. Both percent MW0 and percent MW1 will result in a double integer, but only a single percent MW0 or percent MW1 will result in an integer.

Real

32 bits is also a valid format in this case. The main distinction between real and double integers is that a real variable can be set to a decimal value directly.

The result will range between -3.4028235E+38 and 3.4028235E+38. A real format, like a double integer, uses two memory words.

Float

A float is also a data type that is made up of a number that is not an integer since it contains a fraction in decimal notation.

One of the most prevalent expert definitions is that a float “contains numbers on both sides of the decimal.” However, float denotes decimal fractions whereas integer does not.

Some argue that the float data type is utilised in computer programming when more accuracy than integers can give is required.

Signed Integer

Integers containing a “+” or “-” sign are called signed integers. When n bits are used to represent a signed binary integer number, one bit represents the number’s sign, and the remaining (n - 1) bits reflect the number’s magnitude.

In a computer, there are several ways to represent signed numbers.

  • Sign and magnitude
  • One’s complement
  • Two’s complement