Differences between military time and 24 hour time

Military time is very similar to 24 hour time.

There are 2 differences between the military time setting and the 24 hour time setting. Military time uses a leading zero and doesn’t have a colon, while 24 hour time uses a colon but not a leading zero. So 8 o’clock am is shown as 0800 in military and 8:00 in 24 hour time. 8 pm would be 2000(military) and 20:00(24 hour).

Knowing these differences will help with deciding which time format will be of most use for specific purposes.

Difference between ‘int main()’, ‘void main()’ and ‘main()’ function in the C programming language

Solution 1:

Like any other function, main is also a function but with a special characteristic that the program execution always start from main. So the function main needs arguments and a return type. These int and void are its return type. Void means it will not return any value, which is also allowed.
But if want to know whether the program has terminated successfully or not, we need a return value which can be zero or a non zero value. Hence the function becomes int main () and is recommended over void main ().

Next question will strike into our minds will  be –
The same thing we can do by using getch() (for void main). then why int main is suggested?? Is there any advantage of int main over void main??

Because, the standard statements are:
int main(void)
int main(int argc, char **argv)

You can also use main() simply that means same as int main()..
int main() returns an exit value to compiler and works on most compilers.
And getch() as you mentioned has nothing to do with it. It gets character input on screen or else holds screen in other words

Solution 2:

void main() { ... } is wrong. If you’re declaring main this way, stop. (Unless your code is running in a freestanding environment, in which case it could theoretically be correct.)

main() { ... } is acceptable in C89; the return type, which is not specified, defaults to int. However, this is no longer allowed in C99. Therefore…

int main() { ... } is the best way to write main if you don’t care about the program arguments. If you care about program arguments, you need to declare the argc and argv parameters too. You should always define main in this way. Omitting the return type offers no advantage in C89 and will break your code in C99.

C Thumb rule and standards followed:

1. int main() is preferred over void main(), as per standards, and most new compilers supports int main() rather than void main().
2. int main() can help to return the error code if your program fails due to some error.

Difference Between Declaration and Definition of a Variable in C

Declaration specifies the properties of a variable.

For example:

    int x;              /* x is an integer */
    int roll_no[];      /* roll_no is an array of integers */

Definition declares a variable and causes the storage to be allocated.

For example:

    int x = 10;         /* x is declared as an integer and allocated space and initialized to 10 */
    int roll_no[100];   /* roll_no is declared as an array of integers, allocated space for 100 integers */

 

Quick and easy Left and Right shift operator

Left Shift

x = x * 2^value (normal operation)

x << value (bit-wise operation)

Example:

x = x * 16 (which is the same as 2^4)

The left shift equivalent would be x = x << 4

Right Shift

x = x / 2^value (normal arithmetic operation)

x >> value (bit-wise operation)

Example:

x = x / 8 (which is the same as 2^3)

The right shift equivalent would be x = x >> 3

What is the REPL?

A read–eval–print loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.

A Quick Summary of Python PEP 8 Programming standards

Indentation, line-length & code wrapping

  • Always use 4 spaces for indentation (don’t use tabs)
  • Write in ASCII in Python 2 and UTF-8 in Python 3
  • Max line-length: 72 characters (especially in comments)
  • Always indent wrapped code for readablility
# Good:
result = some_function_that_takes_arguments(
    'argument one,
    'argument two',
    'argument three'
)

# Bad:
result = some_function_that_takes_arguments(
'argument one,
'argument two', 'argument three')
result2 = some_function_that_takes_arguments('argument one', 'argument two', 'argument three')

Imports

  • Don’t use wildcards
  • Try to use absolute imports over relative ones
  • When using relative imports, be explicit (with .)
  • Don’t import multiple packages per line
# Good:
import os
import sys
from mypkg.sibling import example
from subprocess import Popen, PIPE # Acceptable
from .sibling import example # Acceptable

# Bad:
import os, sys # multiple packages
import sibling # local module without "."
from mypkg import * # wildcards

Whitespace and newlines

  • 2 blank lines before top-level function and class definitions
  • 1 blank line before class method definitions
  • Use blank lines in functions sparingly
  • Avoid extraneous whitespace
  • Don’t use whitespace to line up assignment operators (=, :)
  • Spaces around = for assignment
  • No spaces around = for default parameter values
  • Spaces around mathematical operators, but group them sensibly
  • Multiple statements on the same line are discouraged
# Good:
spam(ham[1], {eggs: 2})
if x == 4:
    print x, y
    x, y = y, x
dict['key'] = list[index]
y = 2
long_variable = 3
hypot2 = x*x + y*y
c = (a+b) * (a-b)
def complex(real, imag=0.0):
    return magic(r=real, i=imag)
do_one()
do_two()

# Bad
spam ( ham[ 1 ], { eggs: 2 } ) # spaces inside brackets
if x == 4 : print x , y ; x , y = y , x # inline statements, space before commas
dict ['key'] = list [index] # space before dictionary key
y             = 2 # Using spaces to line up assignment operators
long_variable = 3
hypot2 = x * x + y * y # Too much space around operators
c = (a + b) * (a - b) # Too much space around operators
def complex(real, imag = 0.0):
    return magic(r = real, i = imag) # Spaces in default values

Comments

  • Keep comments up to date – incorrect comments are worse than no comments
  • Write in whole sentences
  • Try to write in “Strunk & White” English
  • Use inline comments sparingly & avoid obvious comments
  • Each line of block comments should start with “# “
  • Paragraphs in block comments should be separated by a line with a single “#”
  • All public functions, classes and methods should have docstrings
  • Docstrings should start and end with """
  • Docstring one-liners can be all on the same line
  • In docstrings, list each argument on a separate line
  • Docstrings should have a blank line before the final """
def my_function():
    """ A one-line docstring """

def my_other_function(parameter=False):
    """
    A multiline docstring.

    Keyword arguments:
    parameter -- an example parameter (default False) 

    """

Naming conventions

  • Class names in CapWords
  • Method, function and variables names in lowercase_with_underscores
  • Private methods and properties start with __double_underscore
  • “Protected” methods and properties start with _single_underscore
  • If you need to use a reserved word, add a _ to the end (e.g. class_)
  • Always use self for the first argument to instance methods
  • Always use cls for the first argument to class methods
  • Never declare functions using lambda (f = lambda x: 2*x)
class MyClass:
    """ A purely illustrative class """

    __property = None

    def __init__(self, property_value):
        self.__property = property_value

    def get_property(self):
        """ A simple getter for "property" """

        return self.__property

    @classmethod
    def default(cls):
        instance = MyClass("default value")
        return instance

Source: https://www.python.org/dev/peps/pep-0008/#introduction

Operational Amplifier based Integrator Circuit

The description contains information such as design details, equations and practical ideas for the operational amplifier or op amp integrator circuit.

OP-AMP CIRCUITS INCLUDE:

  • Operational amplifier circuits
  • Inverting op-amp
  • Non-inverting op-amp
  • High pass filter
  • Low pass filter
  • Bandpass filter
  • Variable gain amplifier
  • Notch filter
  • Multivibrator
  • Bistable
  • Comparator
  • Schmitt trigger
  • Integrator
  • Differentiator

Operational amplifiers form an ideal basis for creating an integrator circuit.

While it is possible to develop a simple integrator circuit using just a resistor and capacitor, the operational amplifier with its high level of gain enables a far higher performance circuit to be created.

The op amp based circuit is able to give much higher levels of linearity, and a much greater elvel of integrity in its output than one using just the minimum number of components.

Electronic integrator basics

In most op amp circuits, the feedback that is used is mainly resistive in nature with a direct resistive path forming at least part of the network. However for the integrator this is not the case – the component providing the feedback between the output and input of the op amp is a capacitor.

As the name of the op amp integrator implies, it performs a function that is an electronic equivalent to the mathematical integration function. In fact electronic integrator circuits can be used in analogue computers.

In terms of their operation, the circuit produces an output that is proportional to the integral of its input voltage with respect to time.

This means that the output voltage at any time is determined by the start output voltage, the length of time the input voltage has been present and the value of the input voltage.

The basic idea behind an integrator circuit is shown below. Although there are a few changes for the op amp integrator circuit, this concept is what is behind its operation.

Integration of voltage
Integration of voltage

From the diagram, it can be seen that while the input remains at zero, so does the output. However when a step input voltage is applied to the input, the output rises. When the step input returns to zero, the output remains at the voltage it last attained.

Operational amplifier integrator circuit

The basic operational amplifier integrator circuit consists of an op amp with a capacitor between the output and the inverting input, and a resistor from the inverting input to the overall circuit input as shown.

Op amp integrator circuit
Op amp integrator circuit

One of the first points to note is that as the signal is applied to the inverting input, the output of the circuit is the inverse of a basic CR integrator network.

Output from op amp integrator circuit
Output from op amp integrator circuit

 

Design calculations

The primary calculation required for the circuit is to determine the output voltage for a given input voltage for a given time.

Op amp integrator design equation

Where:
Vout = output voltage from op amp integrator
Vin = input voltage
T = time after start of application of voltage in seconds
R = resistor value in integrator in Ω
C = capacitance of integrator capacitor in Farads
c = constant of integration and in this case is the output starting voltage.

The negative sign in the equation reflects the inversion resulting from the use of the inverting input of the op amp.

Saturation

It is obvious that the output of the integrator cannot rise indefinitely as the output will be limited.

The output of the op amp integrator will be limited by supply or rail voltage and the saturation of the op amp itself, i.e. how close to the rails the output can swing.

When designing one of these circuits, it may be necessary to limit the gain or increase the rail voltage to accommodate the likely output voltage swings.

While small input voltages and for short times may be acceptable, care must be taken when designing circuits where the input voltages are maintained over longer periods of time.

Op amp integrator saturation point
Op amp integrator saturation point

Reset facility

It is sometimes necessary to have a means whereby the op amp integrator can be reset to zero.

The addition of a reset facility or capability is very easy to achieve. It is accomplished by simply adding a switch across the integrator capacitor. This has the effect of discharging the capacitor and thereby resetting the overall integrator.

Op amp integrator with reset switch
Op amp integrator with reset switch

The reset switch can be implemented in a variety of ways. Obviously a simple mechanical switch can be used, but it is also possible to use semiconductor switches. These are typically FET based switches because they have a very high off resistance and can be controlled as switches in this type of application more easily.

voltage swing

Swing is the difference of maximum output voltage and minimum output voltage. Maximum possible swing in output you can have is VDD-VSS. where VDD is most positive voltage and VSS is most negative voltage. It does not mean that your swing is VDD-VSS. It may be smaller than this. This depends on circuit design.
For CMOS logic family it is VDD-GND. It means CMOS logic family have full voltage swing.

For example:

Question: op-amp741 why Voutmax= VCC-Vce(sat)13-Vbe14 ? Isn’t it:VCC-Vce(sat)14?

Answer: The output circuitry of op-amps have one transistor pulling the output pin up to +Vcc and another transistor that pulls the output pin down to -Vcc. So the output pin can only go to Vcc – VCE sat in each direction. It is unusual to run a “linear” amplifier right up to the output transistors saturation point, because the risk of lock up (negative feedback turning into positive), so it is safer to allow a margin between the Vout and the VCC.

Rail voltage

A voltage “rail” refers to a single voltage provided by the PSU (short for power supply – actually it stands for power supply unit). An ATX PSU has one 3.3 volt rail. It also has one 5 volt rail. The 3.3 volt rail has its own circuitry in the PSU which generates the voltage.

Rail to Rail Voltage Meaning???

Answer 1:

Rail = DC supply rail.

If the circuit operates with one supply rail and ground – then ground is
considered to be one of the rails.

Answer 2:

A “rail” here is a power supply. Rail-to-rail just means the full
range of voltages between the most positive and the most negative
power supply voltages present.

Most opamps, for example, if powered from +15 and -15 rails, can’t
make outputs that go all the way from +15 to -15… they usually lose
a volt or two on each end. A r-r-output opamp can output almost all
the way.

Simple Real time analogy for rail to rail voltage:

In Inter-Modal Transportation, Rail to Rail means a Bus, just like in
electronics. If I wished to travel by rail from City A to City B, I
might have to take the bus in order to resume Rail travel.

Inter-Modal Transportation Means

Inter-modal means “involving two or more different modes of transport in conveying goods”.

Intermodal freight transport involves the transportation of freight in an intermodal container or vehicle, using multiple modes of transportation (rail, ship, and truck), without any handling of the freight itself when changing modes.

Complete and easy explanation – Difference amplifier and Voltage follower

An op-amp with no feedback is already a differential amplifier, amplifying the voltage difference between the two inputs. However, its gain cannot be controlled, and it is generally too high to be of any practical use. So far, our application of negative feedback to op-amps has resulting in the practical loss of one of the inputs, the resulting amplifier only good for amplifying a single voltage signal input. With a little ingenuity, however, we can construct an op-amp circuit maintaining both voltage inputs, yet with a controlled gain set by external resistors.

If all the resistor values are equal, this amplifier will have a differential voltage gain of 1. The analysis of this circuit is essentially the same as that of an inverting amplifier, except that the noninverting input (+) of the op-amp is at a voltage equal to a fraction of V2, rather than being connected directly to ground. As would stand to reason, V2 functions as the noninverting input and V1 functions as the inverting input of the final amplifier circuit. Therefore:

If we wanted to provide a differential gain of anything other than 1, we would have to adjust the resistances in both upper and lower voltage dividers, necessitating multiple resistor changes and balancing between the two dividers for symmetrical operation. This is not always practical, for obvious reasons.

Another limitation of this amplifier design is the fact that its input impedances are rather low compared to that of some other op-amp configurations, most notably the noninverting (single-ended input) amplifier. Each input voltage source has to drive current through a resistance, which constitutes far less impedance than the bare input of an op-amp alone. The solution to this problem, fortunately, is quite simple. All we need to do is “buffer” each input voltage signal through a voltage follower like this:

Now the V1 and V2 input lines are connected straight to the inputs of two voltage-follower op-amps, giving very high impedance. The two op-amps on the left now handle the driving of current through the resistors instead of letting the input voltage sources (whatever they may be) do it. The increased complexity to our circuit is minimal for a substantial benefits

Voltage follower

A voltage follower (also called a unity-gain amplifier, a buffer amplifier, and an isolation amplifier) is a op-amp circuit which has a voltage gain of 1.

Voltage Follower

This means that the op amp does not provide any amplification to the signal. The reason it is called a voltage follower is because the output voltage directly follows the input voltage, meaning the output voltage is the same as the input voltage. Thus, for example, if 10V goes into the op amp as input, 10V comes out as output. A voltage follower acts as a buffer, providing no amplification or attenuation to the signal.

Voltage Follower Input and Output

What is the Purpose of a Voltage Follower

One may ask then, what is the purpose of a voltage follower? Since it outputs the same signal it inputs, what is its purpose in a circuit? This will now be explained.

An op amp circuit is a circuit with a very high input impedance. This high input impedance is the reason voltage followers are used. This will now be explained.

Voltage Followers Draw Very Little Current

When a circuit has a very high input impedance, very little current is drawn from the circuit. If you know ohm’s law, you know that current, I=V/R. Thus, the greater the resistance, the less current is drawn from a power source. Thus, the power of the circuit isn’t affected when current is feeding a high impedance load.

Let’s look at both illustrations below:

The below circuit is a circuit in which a power source feeds a low-impedance load.

Power source with low impedance load

In this circuit above, the load demands and draws a huge amount of current, because the load is low impedance. According to ohm’s law, again, current, I=V/R. If a load has very low resistance, it draws huge amounts of current. This causes huge amounts of power to be drawn from the power source and, because of this, causes high disturbances and use of the power source powering the load.

Now let’s look at the circuit below, connected to an op-amp voltage follower:

Power Source with High Input Impedance

This circuit above now draws very little current from the power source above. Because the op amp has such high impedance, it draws very little current. And because an op amp that has no feedback resistors gives the same output, the circuit outputs the same signal that is fed in.

This is one of the reasons voltage followers are used. They draw very little current, not disturbing the original circuit, and give the same voltage signal as output. They act as isolation buffers, isolating a circuit so that the power of the circuit is disturbed very little.

Voltage Followers Are Important in Voltage Divider Circuits

So, current, as explained above, is one of the reasons voltage followers are used. They simply don’t draw a lot of current, so they do not load down the power source.

Another reason voltage followers are used because of their importance in voltage divider circuits. This again deals with ohm’s law. According to ohm’s law, voltage= current x resistance (V=IR).

In a circuit, voltage divides up or is allocated according to the resistance or impedance of components.

Because an op amp has a very high input impedance, the majority of voltage will fall across it, (since it’s so high impedance). So it’s very valuable when used in a voltage divider circuit because strategically doing so can allow a designer to supply sufficient voltage to a load.

This will now be illustrated so you can see.

So let’s say we have a circuit shown below which represents a voltage divider with a load attached to the output.

Voltage divider circuit that does not work

So the above circuit will not work and it will be explained now why not.

So in the circuit above, we have a voltage divider between the top 10KΩ resistor and the bottom 10KΩ and 100Ω resistors in parallel. So the voltage divider equation is characterized by the following equation, 10KΩ and 10KΩ||100Ω.

Doing the math across the 10KΩ and the 100Ω resistors in parallel gives us, 10KΩ || 100Ω = (10KΩ)(100Ω)/1.1KΩ= 99.01Ω ~ 99Ω.

So we next have a voltage divider between the 10KΩ resistor and the 99Ω resistor.

We now can use the voltage divider formula to see how much voltage will fall across the top 10KΩ resistor and the bottom 10KΩ resistor in parallel with the 100Ω resistor.

The voltage divider formula for the voltage across the top 10KΩ resistor is, V= 10V(10KΩ)/(10KΩ+99Ω)= 9.9V.

The voltage divider formula for the voltage across the bottom 10KΩ resistor and the 100Ω resistor is, V= 10V(99Ω)/(10,099Ω)= 0.098V or 98mV.

Remember, we use 99Ω because this is the equivalent resistance of the 2 resistors (the 10KΩ resistor and the 100Ω resistor in parallel).

Because the resistors are in parallel, they have the same voltage across each other, which is 98mV.

Now let’s say the load needs about 5V to operate. You can see based on the calculation, there will not be sufficient voltage at the output. As we calculated, we had 98mV as our voltage across the load at the output.

The 100Ω resistance (load) carries down the resistance at the output too low. Therefore, in a voltage divider circuit, the load gets very low voltage, since voltage drops across loads in direct proportion to the resistance (V= IR).

However, if we take out the 100Ω load and instead connect an op amp instead (with its high input impedance), the resistance at the output (which ultimately powers the load) doesn’t get drawn down. So the load can receive sufficient voltage.

Let’s see how this circuit changes now with an op amp, with its high input impedance, and the load connected to the output of the op amp.

This is shown below.

Voltage divider circuit that works

So this circuit above now works.

The voltage divider is now between the top 10KΩ resistor and the 10KΩ resistor and op amp at the bottom.

The op amp virtually offers infinite input impedance. Obviously, it’s not really infinite in real life, but it is hundreds of megohms. Let’s assume it’s 100MΩ, though it can be much more.

So the equation that would characterize our voltage divider is between, 10KΩ and 10KΩ || 100MΩ.

Doing the math on the equivalent parallel resistance of the 10KΩ || 100MΩ resistance gives, (10KΩ)(100MΩ)/(10KΩ + 100MΩ)= 9999Ω ~ 10KΩ.

So we have, 10KΩ || 10KΩ.

Any voltage divider composed of the same 2 resistances gives half the voltage of the power supply. But just to show the math, we have the voltage divider formula, 10V * (10KΩ)/(10KΩ + 10KΩ)= 5V.

So 5 volts falls across the top 10KΩ resistor and 5V falls across the bottom 10KΩ resistor and the 100Ω.

Since the 100Ω and 10KΩ resistor are in parallel, they both receive the same 5V.

So you can see how the op amp allowed us to buffer the output of this circuit so that the load receives the voltage it needs.

So these are the 2 chief reasons we use voltage followers. We either don’t want to load down the power supply and/or we want to buffer the output voltage from a circuit so that a load (especially a low-impedance one) can receive the voltage it needs.

So voltage followers are important to either isolate a circuit so that it doesn’t draw down power or buffer a low impedance load so that it receives sufficient voltage.