Posts

Showing posts from March, 2017

mathajax

Binary to Real number conversion

The number system conversion is carried out for a binary numbers (base-2) into real number (base 10). The input binary bit sequence consists of integer and fraction binary bits separated by a decimal point. The integer bits and fractional bits are converted into decimal value separately and then combined to print real value as a result of given binary bit sequence. The fractional part of binary bits are converted into decimal fraction value by multiplication of the bits by 2 power of negative positional value of the bits. Binary to Real number Conversion - Manual Calculation Given input binary numbers = 1110.1001, converts it into a real number. separate binary bits into integer binary bits and fractional binary bits by a delimiter . (point) binary bits (integer part) = 1110 binary bits (fraction part) = 1001 Binary bits (integer part) into decimal conversion binary bits (integer part)

Real number to Binary conversion

The number system conversion is carried out for a real number to binary number bits. The input real number consists of integer and fraction values separated by a decimal point. The integer value and fractional value are converted into binary separately and then combined to print binary bits as a result of the real number. The fractional decimal number are converted into binary numbers by successive multiplication of the fraction by 2 and resulting string of integer digits is the converted binary numbers. Real number to Binary Conversion - Manual Calculation Given input real number= 14.125, convert it into binary numbers real = integer . fraction separate real into integer and fractional part decimal = 14 fraction = .125 Decimal value (integer) into Binary conversion 2 | 14 | 0 ----------- 2 | 7 | 1 ----------- 2 | 3 | 1 ----------- 1 deci

Signed and Unsigned Decimal to Binary number

Image
It explains how to converts a number from decimal number (base 10) to binary numbers (base 2). The decimal value can be a unsigned (positive) or a signed (negative) decimal numbers. The binary operation, 2's complements used in conversion signed decimal value to binary. signed/unsigned decimal to Binary Conversion - algorithm Initialize binary-bits array Read a decimal-value (positive or negative) value2 = abs(decimal-value) binary-bits = converts value2 into binary IF decimal-value >= 0    print binary-bits ELSE  binary-bits_2'sc = take 2's_complement on binary-bits    print binary-bits_2'sc unsigned decimal to Binary Conversion - example The given positive decimal value is decval=5; converts into binary 4 bits decimal to binary 4 bit conversion steps 1. bits = decval % 2;

Binary 1's and 2's Complement

The binary 1's and 2's complement is carried out on binary numbers to simplify the digital circuits on subtraction operation works as same as addition operation. It is also used in signed decimal to binary conversion. One's or 1's Complement Binary Inversion - binary bits flipping, if a bit is 1, it is inverted into 0 or if a bit is 0, it is inverted into 1. One's Complement - Binary inversion is carried out on each bit in the binary numbers and resultant binary numbers from this operation called One's complement of the binary numbers. Binary One's/1's Complement -Example find one's complement for given binary number = 01010 invert each bit, i.e 1 into 0 and 0 into 1. 01010 - one's complement - 10101 Binary Two's/2's Complement Two's Complement on the binary numbers carr

Complex number Multiplication and Division

Image
The arithmetic operation like multiplication and division over two Complex numbers is explained Complex number Multiplication multiply two complex numbers z1 and z2. note i^2 = -1 z1 = a + bi z2 = c + di z1*z2 = (a+bi) * (c+di) = a*c + a*di + bi*c + bi*di = a*c + a*di + bi*c + b*d*(i^2) = a*c + a*di + bi*c + b*d*(-1) = a*c + a*di + c*bi - b*d = (a*c - b*d) + (a*di + c*bi) Complex number Division divide two c omplex numbers z1 and z2. note i^2= -1 z1 = a + bi z2 = c + di z1 / z2 = (a+bi ) / (c+di) multiply numerator and denumerator by conjugate z2 conjugate z2 = c + (-1)* di = c - di z1 / z2 = (a+bi) (c-di) / (c+di ) (c-di) (a+bi) (c-di) = a*c - a*di + c*bi -bi*di = a*c - a*di + c*bi -b*d*(i^2) =

Complex number Addition and Subtraction

Image
The arithmetic operations addition or subtraction is carried out on the complex numbers by adding or subtracting on respective parts (real and imaginary) of them. Complex numbers Addition Add two complex numbers z1 and z2 z1 = a + bi z2 = c + di z1 + z2 = a + bi + c +di = (a+c) + (b+d)i Complex numbers Subtraction subtract complex numbers z2 from z2 z1 = a + bi z2 = c + di z1 - z2 = (a + bi) - (c+di) = a + bi -c - di = (a-c) + (b-d)i Java code - Complex Addition and Subtraction The following Java codes add and subtract two complex numbers and returns a complex number ,as result of the operation. public class AddSub { public static Complex subtract(Complex C1,Complex C2) { Complex tmp = new Complex(); tmp.real = C1.real - C2.real; tmp.imag = C1.imag - C2.imag; return tmp; } pu

Complex number

Image
A complex number consists of two parts; one is the real part and other imaginary part . The real part is marked on x-axis and the imaginary part on the y-axis on the complex plane. A complex number z= a + bi a - Real part b - imaginary part Complex Conjugate A complex numbers can be converted into complex conjugate by simply multiplying (-1) with imaginary parts . It causes the complex point on first quadrant moves to forth quadrant and vice versa. Similarly,the complex point on second quadrant moves to third quadrant and vice versa. Complex z= a +bi conjugate = a + (-1)bi = a - bi Complex - Absolute An absolute value of a complex number is found by the distance between origin and complex number on the complex plane. A complex number = a + bi Absolute value = sqrt ( a^2 + b^2 ) The Java programming code - Complex number The fol

Orthonormal vector

Image
A two vectors can be orthonormal to one another in other words, These vectors are perpendicular to each other and also their vector length equal to 1. To detect whether these two vectors are orthonormal or not , the vectors inner-product and vector length are used. If the result the inner-product is 0 (zero) and norm is 1 (one), the two vectors are orthonormal , otherwise not. Vector X Vector Y Vector Inner Product Vector norm or length Java code - Orthonormal The following Java code finds two vectors X and Y are orthonormal or not to each other by inner-product and norm of these two vector. A vector is defined in Java program by a integer array or a double array. Vector X = [1, 0] Vector Y = [0, 1] find inner product of vector X and Y X.Y = 0 find norm of vector X |X| = 1 find norm of vector Y |Y| = 1 if |X| = 1,|Y| = 1 and X .Y = 0 vector X and Y are orthonormal imp

Orthogonal vector

Image
A two or more vectors can be orthogonal to one another in other words, These vectors are perpendicular to each other. To detect whether these two vectors are orthogonal or not , inner-product of these two vectors is used. If the result the inner-product return 0 (zero), these two vectors are orthogonal, otherwise not. vector X vector Y Two vectors X and Y Orthogonal Java code - Orthogonal The following Java code finds two vectors X and Y are orthogonal or not to each other by inner-product of these two vector. A vector is defined in Java program by a integer array or a double array. import java.util.Arrays; public class Vector { public static boolean isorthogonal( double vec[], double vec2[]) { boolean ortho =false; double inp=0.0; for ( int n=0;n<vec.length;n++) inp = inp + vec[n] * vec2[n]; if ( inp ==0 ) ortho=true; return ortho; } public static boolean isorthogonal( int

Vector normalization - Unit vector

Image
A vector can converted into unit vector by vector normalization in which each elements of the vector is divided by that vector's norm or length . Vector X Unit Vector X Java code - vector normalization The following code converts a vector into unit vector by vector normalization . A vector is defined in Java program by a integer array or a double array. Example Vector X = [5.0, 1.2, 2.0] , find unit vector of X by normalization. 1. find vector X norm || X || = sqrt ( 5.0^2 + 1.2^2 + 2.0 ^2 ) = sqrt ( 25.0 + 1.44 + 4.0 ) = sqrt ( 30.44) = 5.5172 2 Unit vector X = [ 5.0/5.5172 , 1.2/5.5172 , 2.0/5.5172] = [ 0.9062, 0.2175, 0.3625]. import java.util.Arrays; public class Vector { public static double [] unit_vector( double vec[]) { int nelement = vec.length; double uvec[] = new double [nelement]; double nrm =0

Vector Inner product

Image
A matrix product of two vectors X and Y are called inner product that results a scalar output. The two vectors X and Y must have the same number of elements in order to measure inner product these two vectors. A vector X has n elements A vector Y has n elements Inner product of Two vectors X and Y or or Java code - vector inner product The following Java code inner product of two vectors having same number of elements . The vectors can be defined in Java program by a integer array and a double array. import java.util.Arrays; public class Vector { public static double innerproduct( double vec[], double vec2[]) { double inp=0.0; for ( int n=0;n<vec.length;n++) inp = inp + vec[n] * vec2[n]; return inp; } public static int innerproduct( int vec[], int vec2[]) { int inp=0; for ( int n=0;n<vec.length;n++) inp = inp + vec[n] * vec2[n]; return inp;

Vector norm

Image
To measure the length of a vector is called the vector norm , in which length is measured from the origin (0,0) to the vector point on a plane. The following equation are used to measure length of a vector by 1-norm and 2-norm respectively. 1-norm Equation The vector length is measured by the absolute sum of the vector's elements or 2-norm Equation The 2-norm is also called as euclidean norm and is measured by root of squared sum of the vector's elements. or Java code - vector norm The following Java code finds a vector norm1 and norm2 . A vector is defined in Java program by a integer array and a double array. import java.util.Arrays; public class Vector { public static double norm1( double vec[]) { double nrm =0.0; for ( int n=0;n<vec.length;n++) nrm += Math.abs(vec[n]); return nrm; } public static int norm1( int vec[]) { int nrm =0; for ( int n=0;n<vec.length;n++) nrm += Math.abs(vec[n]);

Simple Java Lab programming List and Explanation

The cljavacode (Computer language Java code) has recently started and will regularly post Java programming code on different domain Lab code/Algorithm/Data mining/Optimization/Image processing for engineering students and all curious learner. List of Java Lab Code Roots of Quadratic Equation It explains how compute to root of quadratic equation ax+by+c of given arguments a ,b and c. Biggest number in array of Integers The Java code finds a biggest number in array switch case string The Java code demonstrates simple calculator using switch case with conditional string constant switch case integer The Java code demonstrates switch case integer using object member function access. switch case char The Java code demonstrates switch case char for application of splitting vowels and consonants from a argument string. Temperature conversion The Java code demonstrates the conversion between Celsius to Fahrenheit and vice versa using temperature co

Java Lambda expression - Filtering

Image
A lambda expression is an anonymous function which performs arithmetic or relational operation over an array of data in sequential or parallel manner . It replaces for-loop like operation over array objects. lambda expression Stream Object The array of data might be a java primitive data type (integer or long or double) or a java collection object (ArrayList). In order to execute the lambda expression over array of data , we need a Stream object ( IntStream, LongStream or DoubleStream ). The Java program test Java-8 lambda expression filtering operation over array of integers randomly generated in the range [0 -1000] The class Filtering defined the following five member function for search on dataset,integer arrays. they are,          1. greater      2. lesser      3. range      4. grtequ (greater than and equal)      5. lerequ(lesser than and equal)   An Object of class Filtering is initialized with 20 randomly integers generated from random objec

Java Lambda Expression - Aggregation

Image
A lambda expression is an anonymous function which performs arithmetic or relational operation over an array of data in sequential or parallel manner . It replaces for-loop like operation over array objects. lambda expression Stream Object The array of data might be a java primitive data type (integer or long or double) or a java collection object (ArrayList). In order to execute the lambda expression over array of data , we need a Stream object ( IntStream, LongStream or DoubleStream ). The Stream object can be obtained by many ways, however, an example shown here. An array variable X initialized with random integers int X [] = { 48, 21, 23, 45, 53, 14, 18, 34, 11, 19,21,23,53 }; IntStream object is obtained by passing X as a argument to Arrays.stream function. IntStream intstream =Arrays.stream(X) An array variable X2 initialized with random integers double X2 [

Java File Write Operation

The Java program explains how to write text content into a new file on the disk using the FileOutputStream object which has different write functions operation. The following basic file operation used in this program. File Create File write operation in Java is done while creating an instance/object to the FileOutputStream by invoking constructor function with filepath a as argument. If the file is already found on specified file path, The FileOutputStream object truncates content of the file. File Write and close After creating an instance of the FileOutputStream class, it supports file write and close operation and also supports three ways of writing bytes into the file. They are, write single byte , write the array of bytes with its index and length and write all bytes in an array into the file The Java program is an example of write a byte into the file. The byte is read from user through keyboard. import java.io.FileOutputStream; import