Skip to main content

Integer Numbers in Programming Language



An integer variable may be defined to be of type short, int, or long. The only difference is that an int uses more or at least the same number of bytes as a short, and a long uses more or at least the same number of bytes as an int. For example, on the author’s PC, a short uses 2 bytes, an int also 2 bytes, and a long 4 bytes.

short age = 20;
int salary = 65000;
long price = 4500000;

By default, an integer variable is assumed to be signed (i.e., have a signed representation so that it can assume positive as well as negative values). However, an integer can be defined to be unsigned by using the keyword unsigned in its definition. The keyword signed is also allowed but is redundant.

unsigned short age = 20;
unsigned int salary = 65000;
unsigned long price = 4500000;


A literal integer (e.g., 1984) is always assumed to be of type int, unless it has an L or l suffix, in which case it is treated as a long. Also, a literal integer can be specified to be unsigned using the suffix U or u. For example:

1984L 1984l 1984U 1984u 1984LU 1984ul

Literal integers can be expressed in decimal, octal, and hexadecimal notations. The decimal notation is the one we have been using so far. An integer is taken to be octal if it is preceded by a zero (0), and hexadecimal if it is preceded by a 0x or 0X. For example:


92 // decimal
0134 // equivalent octal
0x5C // equivalent hexadecimal

Octal numbers use the base 8, and can therefore only use the digits 0-7. Hexadecimal numbers use the base 16, and therefore use the letter A-F (or a-f) to represent, respectively, 10-15. Octal and hexadecimal numbers are calculated as follows:

0134 = 1 × 82 + 3 × 81 + 4 × 80 = 64 + 24 + 4 = 92
0x5C = 5 × 161 + 12 × 160 = 80 + 12 = 92

Comments

  1. Integer data type is used to store a value of numeric type. Memory size of a variable of integer data type is dependent on Operating System, For example size of an integer data type in C in a 32 bit computer is 4 bytes whereas size of integer data type in 16 bit computer is 2 bytes. learn C programming

    ReplyDelete

Post a Comment

Give your valuable Comment...

Popular posts from this blog

Object-Oriented Programming and JAVA Programming Language

  Object-Oriented Programming and:   Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, olymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option. JAVA Programming Language: Object-oriented programming is at the core of Java. In fact, all Java programs are object-oriented, this isn’t an option the way that it is in C++, for example. OOP is so integral to Java that you must understand its basic principles before you can write even simple Java programs. Therefore, this chapter begins with a discussion of the theoretical aspects of OOP.

Read or input form user in Java using BufferedReader

 BufferedReader use to read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In Java  BufferedReader is a efficient method to read an input. Here given a short example to read a string from user and print it: package palindrome; import java.io.BufferedReader; import java.io.InputStreamReader; public class  inputExample   {     public static void main(String[] args) throws Exception {    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String s = new String();       s =br.readLine();     System.out.println(s);     } }

Absolute value and Floating-point absolute value function in C Programming Language

Absolute value function in C Programming Language is abs(i), Its return the absolute valu of i. where  i  is any positive or negative  number. It is integer type function. The include file of abs(i) is stslib.h Observe under program: #include<stdio.h> #include<stdlib.h> int main(void) { int a; scanf("%d",&a); printf("%d",abs(a)); } Here I use a integer number. Input it by scanf and print the Absolute value by abs() function. Floating-point Absolute value function in C Programming Language is fabs(i), Its return the absolute valu of i. where  i  is any positive or negative  Floating-point number. It is double integer type function. The include file of fabs(i) is math.h Observe under program: #include<stdio.h> #include<stdlib.h>  int main(void) { float a; scanf("%f",&a); printf("%.2f",fabs(a)); } Here I use a integer number. Input it by scanf and print the Floating-point Absolute value b