answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

What is a cell cursor?

A cursor that is used when selecting a whole cell in an excel spreadsheet.

How do you use bitwise operators to calculate 15 plus 7?

Normally you wouldn't, you'd simply use the built-in addition operator (+):

x = 15 + 7; // e.g., x = 22

However, behind the scenes, the computer uses bitwise operations to determine the sum and it is presumed the question relates to how this is actually achieved. In other words, how can we emulate these machine-level operations in code?

We start with a half-adder. A half-adder has two input bits, the two bits being summed (denoted A and B), and two output bits, the sum bit and the carry-out bit (denoted S and Cout). The half-adder truth table looks like this:

A + B = S, Cout

0 + 0 = 0, 0

0 + 1 = 1, 0

1 + 0 = 1, 0

1 + 1 = 0, 1

The sum bit is determined using a XOR gate (A XOR B) while the carry-out bit is determined using an AND gate (A AND B).

By itself, a half-adder only works for the least-significant bit of a sum (it is just a 1-bit adder after all). To sum multi-bit values we need to implement a full-adder for each bit in the sum. A full-adder is more difficult to implement than a half-adder because it has three inputs rather than just two.

One of the inputs is the carry-in bit (denoted Cin), which is actually the Cout bit from the full-adder for the next least-significant bit. Thus to sum two multi-bit values we use a cascade of full-adders, one for each bit in the sum, where the Cout from one full-adder becomes the Cin for the next.

A full-adder has the following truth table:

Cin + A + B = S, Cout 0 + 0 + 0 = 0, 0

0 + 0 + 1 = 1, 0

0 + 1 + 0 = 1, 0

0 + 1 + 1 = 0, 1

1 + 0 + 0 = 1, 0

1 + 0 + 1 = 0, 1

1 + 1 + 0 = 0, 1

1 + 1 + 1 = 1, 1

A full-adder is implemented using two half-adders joined by an OR gate. Input bits A and B pass through the first half-adder to produce a partial sum. The SUM bit of that half-adder then passes through the second half-adder along with the Cin bit to produce the final SUM bit of the full-adder. Meanwhile, the Cout bits from both half-adders pass through an OR gate to determine the Cout bit of the full-adder. That is, if the Cout bit is set by either of the half-adders, then the Cout must also be set for the full-adder.

Going back to the original example, the sum of 15 and 7, we proceed as follows:

15 + 7 in binary is 00001111 + 00000111

We start at bit 0 (least-significant bit) and pass the inputs through a cascade of full-adders, passing the Cout bit from one full-adder through the Cin to the next:

Cin + A + B = S, Cout

0 + 1 + 1 = 0, 1

1 + 1 + 1 = 1, 1

1 + 1 + 1 = 1, 1

1 + 1 + 0 = 0, 1

1 + 0 + 0 = 1, 0

0 + 0 + 0 = 0, 0

0 + 0 + 0 = 0, 0

0 + 0 + 0 = 0, 0

Reading the S column upwards we find the sum is 00010110 which is 22 decimal. Note that if the Cout of the final-adder is set, the sum has overflowed

To emulate these machine-level operations in C++, we first need to create a class to hold the two output bits:

struct output {

unsigned sum;

unsigned cout;

};

Note that an unsigned data type will occupy more than one bit, however the only valid values will be 0 or 1. Implementing this as a class would make it easier to maintain this invariant, however we'll use a simple data structure for the sake of brevity.

To implement the half-adder, we use the following code:

output half_adder (unsigned a, unsigned b) {

// both inputs must be in the range [0:1]

return output {a^b, a&b};

}

To implement the full-adder, we use the following code:

output full-adder (unsigned cin, unsigned a, unsigned b) {

// all inputs must all be in the range [0:1]

output one {half_adder (a, b)};

output two {half_adder (one.sum, cin)};

return output {two.sum, one.cout | two.cout};

}

To add two 8-bit values using the full-adder, we use the following code:

unsigned sum_8bit (unsigned a, unsigned b} {

unsigned sum=0;

output out {0, 0};

for (unsigned i=0; i<8; ++i) {

out=full_adder (out.cout, a&1, b&1);

sum|=(out.sum<<i);

a>>=1;

b>>=1;

}

if (out.cout) throw std::range_error {"sum_8bit(): out of range"};

return sum;

}

We can test the code with a simple assertion:

int main() {

assert (sum (15, 7)==22);

return 0;

}

How are three dimensional arrays represented in memory Explain how address of an element is calculated in three dimensional array?

Assuming the array is mapped in contiguous memory, the memory block is divided into equal blocks according to the first dimension, and each of those blocks is divided equally according to the second dimension. The smallest blocks therefore represent a one-dimensional array according to the final dimension.

To look at it another way, a three-dimensional array is a one-dimensional array where every element is a two-dimensional array. And every two-dimensional array is a one-dimensional array where every element is also a one-dimensional array. This concept can also be extended to four-dimensional arrays and beyond (a four-dimensional array being a one-dimensional array where every element is a three-dimensional array).

The address of any element in a contiguous multi-dimensional array is calculated from the type of element in the array and the element index.

If we assume the following three-dimensional array has been declared:

int a[3][4][5];

If we also assume that an int (integer) is a 32-bit value and a byte has 8 bits, then it can be seen there are 3*4*5*32 bits allocated to the array, which is 1920 bits in total or 240 bytes. We can also say that there are 3 arrays of 4*5 integers or, more simply, 3*4 arrays of 5 integers. An array of 5 integers therefore consumes 5*32 bits, which is 160 bits or 20 bytes. The second dimension tells us there are 4 such arrays, which makes 80 bytes, and the third dimension tells us there are 3 of those, which brings us to 240 bytes.

Thus to locate any element, we multiply the last index by 4 (the size of an integer), the middle index by 20 (the size of 5 integers) and the first index by 80 (the size of 20 integers), and add these three results together to obtain the offset from the start of the array. Thus element a[2][3][4] will be found (2*80)+(3*20)+(4*4) bytes from the start of the array, which is 160+60+16 or 236 bytes. This is the address of the last integer in the array, which is fortunate because a[2][3][4] is also the index of the last integer in the array (remember that array indices are zero-based).

The name of the array is also a reference to the start address of the array, thus the start address is a, which is the same as saying the address of element a[0][0][0], which is at offset (0*80)+(0*20)+(0*4), which is obviously 0 bytes from a.

As well as accessing elements by their indices, we can also point at individual elements using pointer arithmetic. Element a[1][2][3] can therefore be found at memory address a+(1*80)+(2*20)+(3*4), which is a+132 bytes. In point of fact, the index notation is simply syntactic sugar for the pointer arithmetic that is actually done behind the scenes.

So much for arrays allocated in contiguous memory. Although there will be few occasions where 240 bytes cannot be allocated easily in contiguous memory, imagine a larger array of integers, say [128][256][512], which is 226 bytes or 64MB. On a 32-bit system, 64MB of contiguous RAM may not be available, so we must split the array into smaller arrays. This is where imagining multi-dimensional arrays as being one-dimensional arrays of one-dimensional arrays comes in handy. If we treat the first two dimensions as a two-dimensional array of integer pointers (each of which is 32-bits), then we only need 128*256*4 bytes, which is only 131,072 bytes or 128kB. Each pointer will reference a separate one-dimensional array of 512 integers, each of which is only 2kB in size (512*4). Although total memory consumption is now 256MB, because the allocation is split into one 128kB allocation and 512 separate 2kB allocations there's a far greater chance the allocation will succeed than if we attempt to allocate 64MB contiguously.

The index notation hasn't actually changed but the underlying pointer arithmetic has. If we assume the pointer array is p[128][256], then referencing p[64][128][256] will return the 257th element of the array pointed to by p[64][128]. This works because the first two dimensions return a pointer to a one-dimensional array of integers. If we suppose that the pointer is x, then the final dimension returns the integer stored at x[256].

The underlying arithmetic is a little cumbersome, but can be broken down as x = (p+(64*(256*4))+(128*4)) + (256*4), which reduces to x = (p+66048) + 1024. Thus the memory address stored at offset 66048 bytes within the pointer array plus the offset 1024 returns the 257th element of the appropriate one-dimensional array of integers.

How does strong typing help in reducing errors in programs?

You mean static typing, not strong typing. Strong typing simply means hit the keys harder!

Static typing means that the compiler knows the type at compile time and can therefore check to ensure that all operations upon those types conform to the operations expected of those types. Thus we cannot inadvertently make a silly error such as trying to multiply two strings together. Static typing also means that the compiler can optimise code to suit the specific types being operated upon, rather than generalising the code for a generic type.

How do you fix a sm bus controller error in windows XP?

This is the System Management Bus Controller, if the error is in the device manager then you will need to install the SM Bus Controller drivers that came with your motherboard, either from a drivers CD or download them. Although, your PC will probably continue to function just fine without doing anything, but in theory it should work better with the drivers installed.

There are 3 step to repair sm bus controller error

If you got sm bus controller error then there is a 94% chance that your computer has registry problems. To repair sm bus controller error you need to follow the steps below:

* Step 1 - Download a Perfect Optimizer,install this error repair tool.

* Step 2 - Click the Repair All Button.It will scan you PC for Free.

* Step 3 - Then click the Repair All Button again and your done! It is very easy to repair sm bus controller error.

Here are the URL of Perfect Optimizer: http://www.fixerror365.com/tidpp-sm_bus_controller_error-zz0005

Is there a way to see any program commands to make sure it is not harmful for your computer or does not belong to any malicious software kinds?

An up-to-date virus scanner will help protect against obviously malicious software, but don't be complacent. The best approach is to simply avoid running any commands or programs that you know nothing about. When advised to execute such a command, always do some research on the command first. The program may not be malicious but running a program you know nothing about can easily cause unintentional problems if not used properly. For instance, the DEL command can delete a specific file but if I told you to execute DEL /Y "*.*" that would delete all the files within the current folder without prompting. Unless you're familiar with the DEL command, it's not entirely obvious what it does. While most command line utilities provide help facilities (such as DEL /?), you cannot rely on this for all programs. Some will just ignore any invalid switches (such as /?) and execute anyway. So always research first. If a program is known as malicious it will quickly show up in a search of the internet, but keep in mind some programs masquerade as legitimate files. Check the file size, location, author, etc, to ensure you're actually dealing with the same file.

Is XML a programming language?

It is programming languages that are referred to in terms of "high level" and "low level".

Extensible Markup Language(XML) is a markup language not a programming language, it is a data formatting specification that makes the presentation of data independent of programs (so that data can be passed between programs).

For this reason the answer to your question is "neither".

Where is the gateway to Foo?

The Gateway is in the bottom of the Konigsee lake in Berchtesgaden National Park in Bavaria Germany

What will you do if a hacker enters a computer?

Try and get a hold of their IP. Get their ISP and report them.

What is the definition of traditional media?

Means of communication that hae existed since before the advent of the new media or the internet. I.E.: print publications, analog broadcast and cable tv

Is it possible to create a program to vote automatically and repeatedly in an on line contest?

Of course. It would be no problem at all for the average college student studying information technology. Of course it would be unethical, but that is your problem.

How do you open a nsd file?

Opening unfamiliar filesTo open a file you must have the program that created it installed.

Find out what the NSD extension comes from( what program makes it).

Once you DL or receive that program you should be able to open the file that was created from it.

What are the advantages and disadvantages of a manual solution and what are the advantages and disadvantages of an ICT solution?

The advantages of an IT solution is that all the data that you have worked on, is stored in a secure area in the computer, however, the manual solution can get easily lost or ripped. The IT solution's presentation is better than of a Manual solution. An IT solution can easily remove any faults typed on the computer. However the Manual Solution has to be either rubbed off if using a pencil making it look messy or sometimes crossed off if using a pen. The IT solution can help people to type essays, coursework, stories etc much quicker than of a manual solution.

What famous people were born in Arizona?

TY DORIS CHUCK NORRIS PASCAL AND HIS BOY FRIEND KANYE WEST

What is the difference between vectors and arrays?

The abstraction are the same. However, the array may be of any objects, while a vector, in narrowed definition, each element is a scalar value (e.g, int, float, double, etc), to fulfill the abs(vector) = aScalarValue property of a vector. An array with the same data type would look exactly the same. But an array of Persons will be difficult to be a vector!

The priestess of Apollo at delphi?

I'm assuming you are referring to the priestess of the Oracle. She was always called Pythia (PIH-thee-ah), regardless of her given name.