answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

The substring method returns?

"[Substr] returns a string object with its contents initialized to a substring of the current object."

Algorithm to check prime?

For all positive values in the range 0 to infinity:

1. If the value is less than 2 then it is non-prime.

2. If the value is even, then it is prime if and only if the value is 2 otherwise it is non-prime.

3. For all other values, if the value can be divided by any prime factor in the half-closed range 3 to the integer of the square root of the value plus 1, such that the prime factor is less than the value, then it is non-prime, otherwise it is prime.

Note that prime factors are always prime so 2 is therefore a prime factor. But 2 can only be a prime factor of an even number, and we eliminated all even values in step 2. Thus when we reach step 3 we know that the value must be greater than 2 and must be odd. Therefore we only need to check for prime factors greater than 2. The first prime after 2 is 3, therefore we start checking from 3.

The end of the range of prime factors is defined as the integer of the square root of the value plus 1. This is because there's no point in testing higher prime factors because if one existed, there must also be a lower prime factor. E.g., 3*5 is 15 but so is 5*3. If 3 is a factor then we can stop checking. If the value were 17, then 3 would not be a factor. But the next prime factor is 5 which is greater than the square root of 17. If a higher factor than 5 existed then it follows that 3 would also be a factor. So if there are no factors below the square root there can be no factors above the square root. The square root itself could be a factor (as is the case with 25), thus we add 1 to create a half-closed range. That is, the start of the range is 3 and all potential factors must be greater than or equal to 3 but must be less than the upper bound. Checking if a value is less than another is quicker than checking if it is less than or equal to another, so the overhead of adding 1 to the upper bound saves time when there are two or more potential factors to test, which in the majority of cases there will be.

If the upper bound is less than or equal to 3, then there can be no prime factors. If the value were 3 then the range of prime factors would be 3 to 2 and 2 is less than 3 so there are no prime factors therefore 3 is prime. For values 5 and 7, the range becomes 3 to 3. 3 is not less than 3 so there are no prime factors thus 5 and 7 are prime. For all odd values greater than 7, the range becomes valid. Thus a value of 9 creates a range of 3 to 4. 3 is a prime factor of 9 thus 9 is not prime. We can stop checking as soon as we find a prime factor.

For 11 and 13, the range is also 3 to 4. 3 is not a prime factor so we move onto the next prime factor. The simplest way to find the next prime factor is to add 2, because all prime factors must be odd. So the next prime factor is 5. But 5 is not less than 4, the upper bound, so neither 11 or 13 have any prime factors and are therefore odd.

For 15, the range is also 3 to 4 but 3 is a prime factor of 15 so 15 is not prime.

For 17 and 19, the range is now 3 to 5. 3 is not a factor and 5 (the next prime) is not less than 5 (the upper bound), so 17 and 19 are prime.

For 21 (range 3 to 5), 3 is a factor so 21 is not prime.

For 23 (range 3 to 5), 3 is not a factor so 23 is prime.

For 25 (range 3 to 6), 3 is not a factor but 5 is, so 25 not prime.

For 27 (range 3 to 6), 3 is a factor so 27 is not prime.

For 29 (range 3 to 6), neither 3 nor 5 is a factor so 29 is prime.

And so on...

What is system error 5 command prompt?

It basically means that you don't have elevated access to the program. Try right clicking CMD and click on "run as administrator" then try the prompt again.

What are the disadvantages of co-ed?

Originally, this question was rightly ' . . co-ed school?'. There can be disadvantages more in schools than higher up.

In the year 2007, I wanted to visit Swiss schools and my friends found a school for me to visit nearby the meeting place - facing the beautiful lake Lucerne in the summer of 2007. This happen to be a Girls School. No problem - I was further curious to find more more about this school. In the mind was 'a girls only school even today?.

Among many things the headteacher (male though) said that girls do mature quicker than the boys and girls do not have adequate mental food while the boys already have much. 'We don't have this problem here' he confidently asserted. Since then my firmness for co-ed has shaken a bit. I removed the word school from the question for easy search-hits but its right because, when people mature, they can cope with the difference with their intelligence - it matters more at school. Its not as important in the later days although we have seen a growing trend that girls are doing better everywhere at all levels in the world.

Who developed the ability to store programs?

The concept was proposed in its modern form by the English scientist Charles Babbage around the middle of the 19th century. Check out Wikipedia or run a Google/Ask/AltaVista search for tons of additional information.

Can someone point me in the right direction to learn about modding games because I'm trying to modify a single player game to have an online component and I don't know how?

First you pick the game you want to mod. then you search google for the "SDK" (software development kit) for that game.

For example if you want to mod half life 2 then google search "Half Life 2 SDK"

SDK's can come with anything from level editors, conversion tools for textures and models, source code for programming, ect.

In your case you seem to be wanting to add a multiplayer component to a single player game which would require custom programming. For this you need to find out what programming language the game is programmed in. Probably C++ then find the source code and learn to reprogram it and compile it.

How are the expanded algorithm and the standard algorithm alike?

The expanded algorithm makes use of the partial products to fully explain place value in multiplication. The standard algorithm which is most commonly used is considered superior and less confusing.

How can you determine the byte offset of a field within a structure?

For C++ you can do this:

#define member_offset(Struct, Field) (&(reinterpret_cast(0)->member))

because the byte offset is usually the structure address + offset, so by setting the address to 0, you get 0 + offset == offset.


AnswerYou should the "offsetof" macro. This is a standard macro that has been a part of the C standard for 20 years now (it's part of C89 and C99), so all C and C++ compilers should support it.

#include
size_t offsetof(type, member);

For example:

struct s { int x, y; };
offsetof(struct s, y);

Algorithm for hill cipher?

  • Hill Cipher is a cryptographic algorithm to encrypt and decrypt an alphabetic text. In this cipher, each letter is represented by a number (eg. A = 0, B = 1, C = 2). To encrypt a message, each block of n letters (considered as an n -component vector) is multiplied by an invertible n × n matrix, against modulus 26.

What is the serial board connector used for?

It's used to connect to a serial device to a computer. The term "serial board" usually refers to an electronic printed circuit board that can be plugged into a computer, in order to attach an external device via a serial interface. In the past, the most common type of serial interface was RS-232, this was used to connect all kinds of devices to computers, most notably modems. These days, RS-232 has been replaced by USB, which stands for Universal Serial Bus.

What is BYTE Code in java?

Java byte code is the code that is output by the Java compiler. Byte code is not machine code, it must be interpreted to create the machine code. This is handled by the Java virtual machine. Pretty much every platform produced today has a Java virtual machine implementation, so the same byte code can be executed upon any machine. Byte code can be regarded as being the native language of the virtual machine, as opposed to machine code which is the native language of the physical machine.

What two devices are considered input devices?

Keyboard, Mouse, Barcode Reader, Scanner - any device that takes user input.

Does hybrid inheritance consist of ANY two types of inheritance?

There are only two types of inheritance to begin with: single inheritance and multiple inheritance. Since they are mutually exclusive there is no such thing as hybrid inheritance.

What type of computer writes and modifies a computer program?

Personal Computer....AKA..... all computers write and mod computer programs that's how they run them.

What is local declaration?

Declarations inside a function is called local declaration

Where is the shortcut area in the windows interface How is it useful for us?

There is no specific "shortcut area" in Windows. You can place shortcuts wherever you like. Shortcuts are useful because they allow us to access programs and data from places that are convenient to us. Typically, we place shortcuts on the desktop, in the start menu and on the taskbar as these places are always accessible.

Why gray code is used in k-map instead of binary code?

The main reason we use Gray code is because adjacent Gray codes only differ by 1 bit. This means that in a Gray encoded truth table, only one input changes between adjacent rows or adjacent columns. More importantly, the rows and columns "wrap around". They are cyclic; the first row immediately follows the last and the first column immediately follows the last, without affecting the 1 input difference between adjacent rows and columns. This cyclic nature means we can imagine a 2-dimensional truth table as a 3-dimensional toroid (like a ring doughnut).

K-maps are all about recognising patterns within complex logic in order to reduce boolean algebra to its simplest form. Gray codes help us achieve that by effectively increasing the number of truth tables whilst maintaining the simplicity of the relationship between adjacent rows and columns. For instance, a 4 input function has just 1 truth table, but it has 16 unique K-maps. The more maps, the easier it is to isolate the logic.

While it is possible to use just one truth table to determine the simplest boolean logic for any given function, the more inputs there are the harder this becomes. However, as the number of inputs increases, the number of K-maps also increases exponentially. But the more K-maps, the easier it is to find one that encapsulates the logic in its simplest form simply by looking for recognisable patterns.

What we want to achieve is a map that can be divided up into rectangular regions such that every region holds at least two truths. If we can adjust the map such that all truths are encapsulated by just one region, so much the better. However, frequently, we need to use several regions. The regions may overlap each other, so long as the truth holds in the overlap.

To understand how it works, let's start with a simple four-input function, f(A,B,C,D) and the following truth-table for that function:

# ABCD = f(ABCD)

0 0000 = 0

1 0001 = 0

2 0010 = 0

3 0011 = 0

4 0100 = 0

5 0101 = 0

6 0110 = 1

7 0111 = 0

8 1000 = 1

9 1001 = 1

A 1010 = 1

B 1011 = 1

C 1100 = 1

D 1101 = 1

E 1110 = 1

F 1111 = 0

The minterms (rows that evaluate 0) are {0, 1, 2, 3, 4, 5, 7, F}

The maxterms (rows that evaluate 1) are {6, 8, 9, A, B, C, D, E}

What we're attempting to do is to create the canonical form of the function such that:

f(A, B, C, D) {

if (is_maxterm (A,B,C,D))

return 1;

else

return 0;

}

In other words, we want the is_maxterm() function to be as simple as possible.

Let's start with the standard truth table laid out in a 4x4 grid with AB input pairs across the columns CD input pairs down the rows:

0000 0100 1000 1100

0001 0101 1001 1101

0010 0110 1010 1110

0011 0111 1011 1111

If we then map this grid to the corresponding outputs of the function, we get the following truth table:

0 0 1 1

0 0 1 1

0 1 1 1

0 0 1 0

We can clearly see that there's just two bits "out of sequence". However, there's no recognisable pattern to the logic. No matter how we divide the group of 1's, we always end up with at least one 1 on its own. That's no use to us because it means all four inputs influence that one truth. We want conditions that use just 1, 2 or 3 inputs only, never all 4 inputs.

Let's re-order those inputs using Gray code sequences instead. Gray codes are binary encodings where each code in the sequence differs by just one bit. Thus instead of the sequence 00, 01, 10, 11, we get 00, 01, 11, 10. We can also reorder the sequence by moving a Gray code from one end of the sequence to the other, thus we get four sequences in all: {00, 01, 11, 10}; {01, 11, 10, 00}; {11, 10, 00, 01} and; {10, 00, 01, 11}. However, let's start with the canonical form:

0000 0100 1100 1000

0001 0101 1101 1001

0011 0111 1111 1011

0010 0110 1110 1010

From that we get the following K-map:

0 0 1 1

0 0 1 1

0 0 0 1

0 1 1 1

That's much better. All the maxterms are grouped together and form three regular groups of two or more truths. That is, the maxterms occupy the 2x2 box in the top right, the 1x2 box in the lower right and the 2x1 box in the middle of row 4. So, as luck would have it, the canonical K-map suits us just fine.

Now that we have a recognisable pattern, we can now work out the maxterms using boolean logic.

In the top right 2x2 box, we can see that the output is 1 when A is 1 and C is 0.

In the lower right 1x2 box, we can see that the output is 1 when A is 1 and B is 0.

In the 2x1 box in the middle of the bottom row, the output is 1 when B and C are both 1 and D is 0.

Note that when A is 1 and B is 0 we also overlap the first condition. However, overlaps are fine. Remember we want to establish the simplest possible logic; excluding overlaps would just overcomplicate the logic unnecessarily.

From this, we can establish our function, f:

f (A, B, C, D) {

if ((A and not C) or (A and not B) or (B and C and not D))

return 1;

else

return 0;

}

Since the if statement is itself a boolean expression, we can simplify even further:

f (A, B, C, D) { return (A and not C) or (A and not B) or (B and C and not D); }

This is obviously a trivial example, but just think how much harder it would be to reduce the logic using just the normal truth table. It can be done, but it is far from trivial.

Is set rate 5.75 an example of an assignment statement in programming?

When you assign a value to a variable that already exists, then it is always considered an assignment, otherwise it is considered an initialisation. The main difference is that an initialisation must instantiate a resource to hold the value, whereas the resource already exists with an assignment. In some cases (especially with badly-designed objects), initialisation may in fact be a two-stage process where, behind the scenes, the resource is first instantiated in an uninitialised or default state before being assigned a value through an assignment operator. C, for instance, always uses a two-stage initialisation whereas C++ can use a one-stage initialisation which is more efficient.

What is terminator on a process flowchart?

the circular square shape is the terminator of a flowchart

Why is every video converter failing to convert avi videos to mp4 in Windows 7?

Try using Handbrake or Freemake video converter:

http://handbrake.fr/

http://www.freemake.com/free_video_converter/

There could be a problem with a certain .avi file you're trying to convert.