Have you ever wondered, how any integer is actually stored in computer memory?
The signed integers are stored in the computers memory using the 2's complement method.
Here is a program that verifies that, computers for storing integers, use 2's complement method.
This program is specifically designed for a compiler that stores the integers in 16 bits, that is 16-bit compilers.
SOURCE CODE:-
/********************************************************************************/#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int main()
{
clrscr();
int arr[16];
int num;
cout<<"ENTER THE INTEGRAL NUMBER OF WHICH YOU WANT TO FIND THE BIT PATTERN : ";
cin>>num;
int i=(num);
int z;
for(int k=15;k>=0;k--)
{
z=i>>k;
int j=1;
arr[k]=z&j;
}
for(k=15;k>=0;k--)
cout<<arr[k];
getch();
return 1;
}
/********************************************************************************/
No comments:
Post a Comment