Tuesday, 27 December 2016

ByRef and ByVal

What is the difference between ByRef and Byval?

When you write a subroutine or function, you can pass variables from your main code to that subroutine or function.


If you want to pass the value of the variable, use the ByVal syntax. By passing the value of the variable instead of a reference to the variable, any changes to the variable made by code in the subroutine or function will not be passed back to the main code. This is the default passing mechanism when you don’t decorate the parameters by using ByVal or ByRef.

If you want to change the value of the variable in the subroutine or function and pass the revised value back to the main code, use the ByRef syntax. This passes the reference to the variable and allows its value to be changed and passed back to the main code.

Global/Local variables

Global variables are declared outside any function, and they can be accessed (used) on any function in the program. Local variables are declared inside a function, and can be used only inside that function. It is possible to have local variables with the same name in different functions.

In computer programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed. The set of all global variables is known as the global environment or global state.

Friday, 9 December 2016

Parity bit Model answer

The sender counts or checks the number of 1's in the bit pattern. If even number of 1's then a 0 parity bit is added. If it if odd then a 1 is added in the parity bit.

The receiver counts 1 checks the number of 1's in the bit pattern / data that is received. If odd then it is identified that an error has occurred and requests the data to be re-sent.
If it is even then it is assumed the data is correct however it does not mean it is correct.

Monday, 5 December 2016

Subroutines


What is it?

A routine or subroutine also referred to as a function, procedure, and subprogram is a portion of code that may be called and executed anywhere in a program. For example, a routine may be used to save a file or display the time. Instead of writing the code for these commonly performed tasks, routines are made and called when these tasks need to be performed. 


What is the difference between a subroutine and a function?

In my mind, the difference between function and subroutine is semantic. That is to say some languages use different terminology. A function returns a value whereas a subroutine does not.

Friday, 2 December 2016

Sampling rate and resolution

Rate-

Sample rate is the number of samples of audio carried per second, measured in Hz or kHz (one kHz being 1 000 Hz). For example, 44 100 samples per second can be expressed as either 44 100 Hz, or 44.1 kHz. Bandwidth is the difference between the highest and lowest frequencies carried in an audio stream.


Resolution-

A 16-bit recording uses 16 bits for each sample. 16 bits can represent 65,536 different numbers and amplitudes, which makes for a much better dynamic range. The sampling resolution is the representation (or size of the numbers) used to write samples in digital sound recording.


Calculating the file size given the sample depth, sample rate, sound time and channels

Formula
File size (bits) = sampling frequency (Hz) x sampling depth (bits) x length of sound (s) x channels

Example
A stereo song has to be recorded at CD quality. The song is 4 minutes and 8 seconds long. How much disk space would the captured song occupy?
Settings for CD quality are:
  • Sampling frequency = 44100 Hz (44.1KHz)
  • Sampling depth = 16 bit

Length of song = 4 x 60 + 8 = 248 seconds
File size (bits) = 44100 x 16 x 248 x 2 = 349977600
File size (bytes) = 349977600 / 8 = 43747200
File size (kilobytes) = 43747200 / 1024 = 42721.88
File size (megabytes) = 42721.875 / 8 = 41.72Mb