How do computers store programs and data using binary digits?
They don't! The 1s and 0s are simply how we interpret the data stored inside a computer. There are no numbers as such inside a computer but in order to store data inside a computer we need to speak the same language as the computer. The only language the computer knows is machine code, which is a binary encoded language, thus the easiest way for humans to notate these binary codes is with the digits 0 and 1. In other words, the 0s and 1s are purely a notational convenience.
Binary codes can be represented using any two distinct symbols. Yes and no, true and false, black and white, or positive and negative are all equally valid representations however these concepts are far too abstract for a computer to understand. We need something more basic, something physical that can be easily represented by electronic means.
A computer's working memory consists of a vast array of cells where every cell has a capacitor and a transistor. The transistor is primarily used to rapidly fill or drain the capacitor of a small electric charge and thus provides us with our two binary representations (1 if full, 0 if empty). Unfortunately, the capacitor cannot hold its charge for long; it will drain away within a few milliseconds of being filled. This is not much use to us because in order to provide a memory we need to maintain state as will as switch states. Fortunately, the transistor can detect how much charge is currently in the capacitor, so if it is above a certain level the transistor can simply refill it. This is achieved through a memory refresh which has to occur at a rate such that capacitors that were filled upon the last refresh cycle still hold enough charge to register for a refill upon the next refresh. Now we have a memory that can maintain state.
If you're wondering about the "Bresenham line algorithm", it is an algorithm (a process used for making a desired result) that plots a geometrical line (consiting of infinate points, as if you draw a straight line on a piece of paper) and translates it to a computer screen (composed of pixels, or video "points" that have a specific amount of sized points) The algorithm is as follows: function line(x0, x1, y0, y1)
boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x0
int deltay := abs(y1 - y0)
int error := -(deltax + 1) / 2
int ystep
int y := y0
if y0 < y1 then ystep := 1 else ystep := -1
for x from x0 to x1
if steep then plot(y,x) else plot(x,y)
error := error + deltay
if error ≥ 0 then
y := y + ystep
error := error - deltax This algorithm was taken from the site http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
What are the different types of capacitors?
Ceramic capacitors, film capacitors, multi-layers ceramic capacitors, electrolytic capacitors, mica capacitors, super capacitors, etc.
-- We're JYH HSU(JEC) Electronics Ltd (or Dongguan Zhixu Electronic Co., Ltd.), an electronic components manufacturer. You may google search "JYH HSU" to find our official website.
How do you connect C offline application with the MySQL database placed at remote server?
We use an online MySQL database for both online and offline applications.
What is the full form of printf or scanf?
int printf (const char *fmt, ...)
or
int scanf (const char *fmt, ...)
To delete an element form an array you simply move everything one place to the left, starting with the element to the right of the element you wish to remove, and then delete the final element by resizing the array. The following code demonstrates this:
#include <iostream>
void DeleteElement(unsigned int** pp,unsigned int& size,unsigned int index)
{
if(size)
{
unsigned int* p=*pp+index;
unsigned int* c=p+1;
std::cout<<"Deleting element index "<<index<<" with value "<<*p<<" from an array of size "<<size<<std::endl;
--size;
while(index++<size)
*p++=*c++;
*pp=(unsigned int*)realloc(*pp,size*sizeof(unsigned int));
}
}
void PrintArray(unsigned int* a,const unsigned int size)
{
std::cout<<"Array: size="<<size<<" { ";
unsigned int i=0;
while(i<size)
std::cout<<a[i++]<<" ";
std::cout<<"} "<<std::endl;
}
int main()
{
// Allocate a dynamic array of size 5:
unsigned int size=5;
unsigned int* a=(unsigned int*)malloc(size*sizeof(unsigned int));
// Initialise array with sorted values (ascending order):
for(unsigned int i=0;i<size;++i)
a[i]=(i+1)*2;
// Print current array:
PrintArray(a,size);
// Delete element 1 (value 2)
DeleteElement(&a,size,1);
// Print current array:
PrintArray(a,size);
// Delete element 2 (value 4)
DeleteElement(&a,size,2);
// Print current array:
PrintArray(a,size);
// Release allocation.
delete[]a, a=NULL;
return(0);
}
Note that static arrays cannot be resized, so to remove an element you need to maintain a count of the active elements, and move inactive elements to the end of the array. The process is similar to the above, except you need to copy the inactive element's value before shifting everything to the left, and then replace the final element's value with the one you saved.
In C++, operations such as this are greatly simplified by using a vector rather than an array. Vectors are effectively the same as dynamic arrays, but are implemented as self-contained objects with member methods to manipulate the contents, thus greatly simplifying your code. Deleting an element is a simple as calling the vector's built-in delete method. Memory management is largely transparent and, because a vector knows its internal size, passing vectors to functions is made that much easier -- you simply pass them by reference.
Simulation of finite state automata to recognize the tokens of control statement?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[8];int s,i,flag=0,loc1=0,loc2=0,j;
clrscr();
printf("Enter any string\n");
gets(a);
for(i=0;i<8;i++)
{
int ch=a[i];
if(ch!=32)
{ loc2=i;
flag++;
}
if(ch==32)
{ s=flag; flag=0;
switch(s)
{
case 2:
if(a[loc1]=='i' && a[loc2]=='f')
printf("STRING HAS if AS A KEYWORD");
break;
case 3:
if(a[loc1]=='f' && a[loc1+1]=='o' && a[loc2]=='r')
printf("STRING HAS for AS A KEYWORD");
break;
default:
printf("not our case");
}
}
}
getch();
}
How do you get the middle number for the turbo c using array?
it depends how you have coded your program as:
if you initialized your array (a) by loop from 0 then
int lb=0,ub=n-1; //n is number of elements in array
int mid=(lb+ub)/2;
printf("middle number is :%d",a[mid]);
if you initialized your array (a) by loop from 1 then
int lb=1,ub=n; //n is number of elements in array
int mid=(lb+ub)/2;
printf("middle number is :%d",a[mid]);
How does the compiler differentiate the statement and function in C programming?
statement should not return a value but function returns a value
Where could one purchase a c string bikini?
Fashion C String is a company that offers very high quality bathing suits, that can fit the needs of any woman looking for that hot sexy look for summer. It is also possible to get great deals for summer checking out what is for sale on eBay.
Can you give a C programm about Shortest seek time first algorithm?
Suppose that a disk drive has 5000 cylinders, numbered 0 to
4999. The drive is currently serving a request at cylinder 143,
and the previous request was at cylinder 125. The queue of
pending requests, in FIFO order, is
86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130
Starting from the current head position, what is the total
distance (in cylinders) that the disk arm moves to satisfy all the
pending requests, for each of the following disk- scheduling
algorithms?
A. FCFS
B. SSTF
C. SCAN
D. LOOK
E. C-SCAN
F. C-LOOK
Answer:
A. The FCFS schedule is 143, 86, 1470, 913, 1774, 948, 1509,
1022, 1750, 130. The total seek distance is 7081.
B. The SSTF schedule is 143, 130, 86, 913, 948, 1022, 1470,
1509, 1750, 1774. The total seek distance is 1745.
C. The SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750,
1774, 4999, 130, 86. The total seek distance is 9769.
D. The LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750,
1774, 130, 86. The total seek distance is 3319.
E. The C-SCAN schedule is 143, 913, 948, 1022, 1470, 1509,
1750, 1774, 4999, 0, 86, 130. The total seek distance is
9985.
F. The C-LOOK schedule is 143, 913, 948, 1022, 1470, 1509,
1750, 1774, 86, 130. The total seek distance is 3363.
Can a basic data type be converted into user defined data type in c?
Yes, but it cannot be done in C as intuitively as it can be done in C++:
struct X {
X (const int i): m {i} {} // converts an int to an X [C++ only]
X& operator= (const int i) { m=i; return *this; } // assign an int to an X [C++ only]
int m;
};
Usage:
X x {42}; // construct X from int
x = 0; // assign an int to an X
In C we must use a conversion function:
struct X convert (const int i) { // convert an int to an X
struct X;
x.m = i;
return x;
}
Usage:
struct X x;
x = convert (42);
How do you access elements of array of structure in a function?
For example:
struct { int fld; } v[2];
v[0].fld = 1;
What is a linked list in data structures?
A linked list is a finite sequence of nodes each of which contains a pointer field pointing to the next node. In many languages, a pointer to the first node must be supplied. In a simply linked list, the pointer in the last node points to nil. In an empty list, the pointer in the first node points to nil. In the current Java implementation,the types of elements which can be added to the list are those of type Object or one of it's subclasses. In Java, the Object class is the superclass from which all other classes are derived. This makes it possible to add elements of almost any type to a list, except the built in primitive data types (int, long, char, boolean, long,double). To add elements of these types, it is necessary to convert them from primitive types to classes, which Java supports quite easily. In order to convert the primitive types to classes method overloading is used. In Java, there can be multiple definitions of a method with the same name but different parameters. The Java interpreter will know the right method to call while running based on the parameters passed by the caller. This process, method overloading, is employed to convert the different data types listed above. The primary advantage of a linked list over an array is that a linked list can grow and shrink as needed. In Java, the creation of new objects for inclusion in the list is dynamic and can easily be accomplished without much overhead. Other languages,however, pay some overhead for the pointers they utilize. Another advantage of a linked list is the flexibility derived from rearranging elements efficiently, though this flexibility is gained at the expense of quick access to any object in the list.
Entity integrity, also known as a check constraint, is a database imposed restriction that the value of a field be limited. For instance, you could say that a number can only be in the range of 1 to 100, and the database would not allow you to insert or modify a row to have a value outside that range.
Referential integrity, also known as a foreign key constraint, is a database imposed restriction that the value of a field be contained in the primary key or a unique key associated with another table. For instance, you could say that a programmer's name be contained in a table of employees, and the database would not allow you to insert or modify a row to have a programmer that is not also an employee. In this example, to clarify, the employee table would contain people that are programmers, as well as analysts, managers, officers, etc.
What is the benefit of randomization in quick sort algorithm?
You don't waste time computing a pivot.
What is the marxist structure?
Marxism is the political philosophy and practice derived from the work of Karl Marx and Friedrich Engels. Any political practice or theory that is based on an interpretation of the works of Marx and Engels may be called Marxism. There is still a significant[citation needed] and vital[citation needed] presence of marxist approaches in academic fields of research, trailing almost as an afterthought; these include anthropology, media studies, Theatre, history, economics, literary criticism, aesthetics and philosophy.[1] The constitution of the Communist Parties and Communist states was grounded in Marxism; the basic difference between Communism in general and Marxism, is that Communism aims at the realization of a "Communist society", while Marxism is a theoretical-practical framework based on the analysis of "the conflicts between the powerful and the subjugated".[2][3] As a consequence of this, there are many scholars and thinkers who use Marxism as a framework for analysis but do not advocate a communist society. While there are many theoretical and practical differences among the various forms of Marxism, most forms of Marxism share: * a belief that capitalism is based on the exploitation of workers by the owners of capital * a belief that people's consciousness of the conditions of their lives reflects material conditions and relations * an understanding of class in terms of differing relations of production, and as a particular position within such relations * an understanding of material conditions and social relations as historically malleable * a view of history according to which class struggle, the evolving conflict between classes with opposing interests, structures each historical period and drives historical change
Why you use octa number system and hexadecimal number system in place of binary number systen?
Why_you_use_octa_number_system_and_hexadecimal_number_system_in_place_of_binary_number_systen
Free software to convert hex code into assembly language?
"http://wiki.answers.com/Q/Free_software_to_convert_hex_code_into_assembly_language"
Where function execution ends in c language?
In C, function execution ends with the return statement or when execution encounters the last brace, }, that matches the opening brace, {. If the function is typed, such as int myfunc(), then encountering the last brace is considered an error, because that sequence returns no value.
Where is timing pointer on 1985 350?
Look down between the water pump and the timing chain cover and you will see it.
What is difference between getimage and putimage in c plus plus?
#include <iostream.h>
#include <conio.h>
# include <process.h> //exit(0)
# include <dos.h>
# include <stdlib.h>
# include <graphics.h>
# include <stdio.h>
int MaxX, MaxY, MidX, MidY ;
int bri[5][20] ;
bricks(); //to display bricks and paddle and bulb rounded form
delbrick(int,int);
int graphmode= CGAHI, graphdriver = CGA; //CGAHI = 640 x 200 (col x row)
void MousePos(int* x)
{ union REGS in,out;
in.x.ax=3;
int86(0x33,&in,&out);
*x=(int)out.x.cx;
}
main()
{
int BallX, BallY, Base1, Base2, dx = 1, dy = -1, OldX, OldY ;
int totallayer[5] = { 10, 20, 30, 40, 50 }, max = 50, layer = 4 ;
int i, flag = 0, speed = 10, score = 0, chance = 4, areareq ;
char *m1, *m2 ; //pointers to memory
initgraph ( &graphdriver, &graphmode, "c:\\tc\\bgi" ) ;
MaxX = getmaxx() ;
MaxY = getmaxy() ;
MidX = MaxX / 2 ;
MidY = MaxY / 2 ;
/* draw the four layer of bricks, the paddle and the ball */
rectangle ( 0, 0, MaxX, MaxY - 12 ) ;
bricks() ;
rectangle ( MidX - 25, MaxY - 19, MidX + 25, MaxY - 12 ) ;
circle ( MidX, MaxY -25, 12 ) ;
/* memory allocation for storing the image of the ball */
areareq = imagesize ( MidX - 12, MaxY - 18, MidX + 12, MaxY - 8 ) ;
m1 =((char*) malloc ( areareq )) ;
/* memory allocation for storing the image of the paddle */
areareq = imagesize ( MidX - 25, MaxY - 7, MidX + 25, MaxY - 1 ) ;
m2 =((char *) malloc ( areareq ) );
/* image of the paddle and the ball is stored into allocated memory */
getimage ( MidX - 12, MaxY - 7 - 12 - 12 + 1, MidX + 12, MaxY - 8 -12,m1 ) ;
getimage ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 1 - 12, m2 ) ;
/* store current position of the paddle and ball */
Base1 = MidX - 25 ;
Base2 = MaxY - 19 ;
BallX = MidX - 12 ;
BallY = MaxY - 7 - 12 + 1 - 12 ;
/* display balls remaining ( initially 3 ) */
gotoxy ( 45, 25 ) ;
cout<< "Balls :" ;
for ( i = 0 ; i < 3 ; i++ )
{
circle ( 515 + i * 35, MaxY - 5, 12 ) ;
}
/* display starting score */
gotoxy ( 1, 25 ) ;
cout<< "Score: ";
gotoxy(16,25);
cout<<score;
while ( !kbhit() )
{
flag = 0 ;
/* saving current x and y coordinates of the ball */
OldX = BallX ;
OldY = BallY ;
/* update ballx and bally to move the ball in correct direction */
BallX = BallX + dx ;
BallY = BallY + dy ;
/* according to the position of ball the layer of bricks isdetermined*/
if ( BallY > 40 )
{
max = 50 ;
layer = 4 ;
}
else
{
if ( BallY > 30 )
{
max = 40 ;
layer = 3 ;
}
else
{
if ( BallY > 20 )
{
max = 30 ;
layer = 2 ;
}
else
{
if ( BallY > 10 )
{
max = 20 ;
layer = 1 ;
}
else
{
max = 10 ;
layer = 0 ;
}
}
}
}
/* if the ball hits the right boundary, move it to the left */
if ( BallX > ( MaxX - 24 - 1 ) )
{
BallX = MaxX - 24 - 1 ;
dx = -dx ;
}
/* if the ball hits the left boundary, move it to the right */
if ( BallX < 1 )
{
BallX = 1 ;
dx = -dx ;
}
/* if the ball hits the top boundary, move it down */
if ( BallY < 1 )
{
BallY = 1 ;
dy = -dy ;
}
/* if the ball is in the area of the bricks */
if ( BallY < max )
{
/* if there is no brick at the top of the ball */
if ( bri[layer][ ( BallX + 10 ) / 32 ] 800 - ( ( 4 - chance ) * 10 ) )
{
outtextxy ( MidX, MidY, "Winner !!" ) ;
if ( score < 800 )
outtextxy ( MidX, MidY + 30, "Try to score 800" ) ;
else
outtextxy ( MidX, MidY + 30, " GREAT!" ) ;
closegraph() ;
restorecrtmode() ;
exit ( 0 ) ;
}
/* introduce delay for few seconds */
delay ( speed ) ;
/* put the image of the paddle at the old coordinates */
putimage ( Base1, Base2, m2, OR_PUT ) ;
/* erase the image of the paddle at the old coordinates */
putimage ( Base1, Base2, m2, XOR_PUT ) ;
MousePos(&Base1);
/* if paddle goes beyond left boundary */
if ( Base1 < 1 )
Base1 = 1 ;
/* if paddle goes beyond right boundary */
if ( Base1 > 588 )
Base1 = 588 ;
/* put the image of the paddle at the proper position */
putimage ( Base1, Base2, m2, XOR_PUT ) ;
}
closegraph(); /* Return the system to text mode */
return(0);
}
bricks()
{
int i, j, lx = 0, ly = 0 ;
for ( i = 0 ; i < 5 ; i++ ) /* 5 rows */
{
for ( j = 0 ; j < 20 ; j++ ) /* 20 columns */
{
rectangle ( lx, ly, lx + 20, ly + 7 ) ;
floodfill ( lx + 1, ly + 1, 2 ) ;
lx = lx + 32 ;
}
lx = 0 ;
ly = ly + 10 ;
}
}
delbrick ( int b, int l )
{
/* b - brick number, l - layer */
setcolor ( BLACK ) ;
rectangle ( b * 32, l * 10, ( b * 32 ) + 20 , ( l * 10 ) + 7 ) ;
rectangle ( b * 32 + 1, l * 10, ( b * 32 ) + 20 - 1, ( l * 10 ) + 7 -1 );
rectangle ( b * 32 + 2, l * 10, ( b * 32 ) + 20 - 2, ( l * 10 ) + 7 -2 );
rectangle ( b * 32 + 3, l * 10, ( b * 32 ) + 20 - 3, ( l * 10 ) + 7 -3 );
rectangle ( b * 32 + 4, l * 10, ( b * 32 ) + 20 - 4, ( l * 10 ) + 7 -4 );
rectangle ( b * 32 + 5, l * 10, ( b * 32 ) + 20 - 5, ( l * 10 ) + 7 -5 );
rectangle ( b * 32 + 6, l * 10, ( b * 32 ) + 20 - 6, ( l * 10 ) + 7 -6 );
setcolor ( CGA_YELLOW ) ;
}
What are easy programming languages for becoming a website and software developer?
Hey,
For website developing you'll want to learn html, javascript, asp and such, start with html and you'll just naturaly get to the other languages. for software developing I highly recommend python, it is the easiest language to start with and very powerful (I started with it).
hope this was helpful and good luck!
roy
What is unsigned data types in turbo c?
The same as an unsigned type in any other implementation of C. An unsigned type is an integer that is guaranteed positive. Normally, the most-significant bit of an integer denotes the sign (positive or negative). Unsigned types use this bit to denote value, effectively doubling the range of positive values over that of the signed equivalent. For instance, a signed char has a guaranteed range of -127 to +127 while an unsigned char has a guaranteed range of 0 to 255.
Note that a signed char typically has a valid range of -128 to +127, however this is only true on systems that utilise twos-complement notation. Those that use the older ones-complement notation have two representations for the value zero (one positive, one negative). Ones-complement simply inverts all the bits of a value to switch the sign of a value, whereas twos-complement adds the value 1 after inverting all the bits. The value zero is denoted as 00000000 in binary. Inverting the bits creates 11111111, which is minus zero on a ones-complement system and -1 on a twos-complement system. -1 + 1 is 0, hence we add 1 on a twos-complement system.