My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Tuesday, January 30, 2018

How to calculate log base 2 ?

The calculator we use, we can find the logarithmic operations like log base e and log base 10. So, the question arises what shall we do if we want to calculate log base 2 or log to the base any number other than log base e and log base 10. The answer is within your calculator. You just need to recall a logarithmic formula read in mathematics. The formula is :
                                       
                                       logd(a) / logd(b) = logb(a)

So, if you want to calculate log(x) with base 2 then use the formula in your calculator as:

                  log10(x) / log10(2) = log2(x)

or, you can use

                   ln(x) / ln(2)= log2(x)


Similarly, you can calculate log to the base any number using above formula.

For example: 
                  log2(4)= ln(4) / ln(2)=2
                          log2(8)= ln(8) / ln(2)=3
                          log2(3)= ln(3) / ln(2)=1.584962501






Friday, January 26, 2018

Is drag and drop the future of programming?



Drag and drop in programming means selecting an object from the given toolbox holding the mouse click, moving it (dragging) on the form given in the software and then finally placing (dropping) at the desired place on the form. This feature comes with GUI (Graphical User Interface) based programming. A form is given to the programmer, and a toolbox containing various components to handle the events occurring in the program. A programmer has to write programs for those events according to the requirements of their program. The components contained in the toolbox could be button, timer, label, textbox, picture box and so on. These may vary for different softwares but the motive will be same, to handle the events. There are many softwares that provide drag and drop platform for programming, for example Visual C++, Visual Basic, Visual C#, MIT App Inventor, Scratch etc.
Day by day new milestones are being achieved in the field of drag and drop programming. It is faster to code in the software having the support of drag and drop. It saves the time which is consumed in creating the components like button, textbox etc. during text programming. In Visual Studio (which provides drag and drop support) ,we can find windows form for Visual C++, Visual C#, Visual Basic to use the drag and drop feature. Drag and drop enables rapid application development which makes this feature even more special. Even some professional software developers are using this platform in their programming. Though Microsoft stopped supporting Visual Basic on April 8, 2008, some programmers still prefer it because of its simplicity in coding and as a result it won technical impact award at the 19th D.I.C.E award in 2016. It shows that to some or more extent, people are preferring easy coding. The development of MIT App Inventor, Scratch and many other similar softwares are the evidences for this. MIT app Inventor, Scratch are even one step ahead than what visual studio offers in terms of drag and drop feature. They actually provide drag and drop along with block based programming. Programmers don’t even have to write code for defining an event in the program. They can simply drag and drop the components on the form given and then they can arrange different blocks, given for each components, to get the desired output. These softwares are cloud based so they are even promoting the concept of cloud computing, which is actually supposed to be the future of computer science. Because softwares using drag and drop are relatively easier than text programming doesn’t mean they are used to build only simple applications. Though the limitations are there for block based drag and drop softwares like MIT App Inventor, Scratch etc, which are still in the phase of development, other softwares like Visual C++, C# are very powerful and highly efficient. We can build powerful video games, database management system, apps for windows, Mac and even for mobile using these softwares.
Considering all those features and advantages of drag and drop based programming software, the question arises, “Is drag and drop the future of programming?”. Are we ready to make a transition from text based programming to drag and drop programming? Don’t we need knowledge of core programming anymore? Are we done with text based programming? A lot of questions arises. It is actually a debatable topic. Yes, of course drag and drop is not going to replace text based programming like C, C++ because the development of drag and drop based programming has been possible because of these text based programming languages only. Even the enhancements and improvements being made in the field of drag and drop based programming are due to continuous hard work of text based programmers who have depth knowledge of core programming and computer system. New revolutions in the field of programming are possible only through text based programming. The one who is expert in programming, find drag and drop annoying because of the use of mouse during programming and large consumption of time in dragging and dropping process. Drag and drop based programming can be used in school level to motivate and attract students towards programming where students don’t have to be worry about syntactic errors and finding bugs in the program. They can give their thoughts a visual shape. They will develop the habit of generating ideas and solving problems. They can enjoy programming rather than directly jumping to some tough languages like C, C++. They can see their thoughts coming alive in the form of programs which will encourage them towards programming and eventually towards Computer Science. When they start programming and making apps in drag and drop environment, they will reach a point where they will realize its limitations and they feel like jumping to a text based programming for further enhancements of their skills in the field of programming and making even more powerful and performance driven softwares. And this transition is not going to make them feel programming as a difficult task because till then they would have developed the habit of generating new and innovative ideas, solving problems with different angles, converting thoughts into programs. It will be just a change of language which can even help them to sort out the limitations of drag and drop and improve its upcoming versions.
So, drag and drop is not the future of programming but, for sure it is going to help in encouraging and producing more creative and innovative programmers in the coming future.


Saturday, January 20, 2018

Computer Organisation & Architecture

PROGRAM IN MATLAB FOR DIVISION OF TWO UNSIGNED INTEGER BINARY NUMBERS
(N-BIT NUMBERS)
To implement non-restoring division algorithm in digital computer


function lab5_coa
n=input('enter n:');
a=input('enter a:');
b=input('enter b:');
c=b;
q=a;
carry=0;
for i=1:1:n
    a(1,i)=0;
end
for i=n:-1:1
    if(c(1,i)==1)
        c(1,i)=0;
    
    else
        c(1,i)=1;
    end
end
for i=1:1:n-1
    x(1,i)=0;
end
x(1,n)=1;
for i=n:-1:1
sum=xor(xor(x(1,i),c(1,i)),carry);
carry=or(and(x(1,i),c(1,i)),and(xor(x(1,i),c(1,i)),carry));
r(1,i)=sum;
end
c=r;

    for i=1:1:n-1
        a(1,i)=a(1,i+1);
    end
    a(1,n)=q(1,1);
    for i=1:1:n-1
        q(1,i)=q(1,i+1);
    end
    carry=0;
    for i=n:-1:1
        sum=xor(xor(a(1,i),c(1,i)),carry);
        carry=or(and(a(1,i),c(1,i)),and(xor(a(1,i),c(1,i)),carry));
        a(1,i)=sum;
    end
%LOOPING CONDITION    
 for count=1:1:n-1
    if (a(1,1)==1)
          q(1,n)=0;
        for i=1:1:n-1
        a(1,i)=a(1,i+1);
        end
    a(1,n)=q(1,1);
    for i=1:1:n-1
        q(1,i)=q(1,i+1);
    end
    
       carry=0;
        for i=n:-1:1
        sum=xor(xor(a(1,i),b(1,i)),carry);
        carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),carry));
        a(1,i)=sum;
        end
    else
        q(1,n)=1;
          for i=1:1:n-1
           a(1,i)=a(1,i+1);
          end
             a(1,n)=q(1,1);
            for i=1:1:n-1
             q(1,i)=q(1,i+1);
            end
             carry=0;
    for i=n:-1:1
        sum=xor(xor(a(1,i),c(1,i)),carry);
        carry=or(and(a(1,i),c(1,i)),and(xor(a(1,i),c(1,i)),carry));
        a(1,i)=sum;
    end
    end
 end
 % After completion of loop for count n-1
 if(a(1,1)==1)
       q(1,n)=0;
      carry=0;
        for i=n:-1:1
        sum=xor(xor(a(1,i),b(1,i)),carry);
        carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),carry));
        a(1,i)=sum;
        end
else
 q(1,n)=1;
 end
fprintf('Remainder =');
disp(a);
fprintf('Quotient=');
disp(q);
end

Computer Organisation & Architecture

PROGRAM IN MATLAB FOR DIVISION OF TWO UNSIGNED INTEGER BINARY NUMBERS (N-BIT NUMBERS)
. To implement restoring division algorithm in digital computer  


function div
n=input('enter n:');
a=input('enter a:');
b=input('enter b:');
c=b;
q=a;
carry=0;
for i=1:1:n
    a(1,i)=0;
end
for i=n:-1:1
    if(c(1,i)==1)
        c(1,i)=0;
    
    else
        c(1,i)=1;
    end
end
for i=1:1:n-1
    x(1,i)=0;
end
x(1,n)=1;
for i=n:-1:1
sum=xor(xor(x(1,i),c(1,i)),carry);
carry=or(and(x(1,i),c(1,i)),and(xor(x(1,i),c(1,i)),carry));
r(1,i)=sum;
end
c=r;
for count=0:1:n-1
    for i=1:1:n-1
        a(1,i)=a(1,i+1);
    end
    a(1,n)=q(1,1);
    for i=1:1:n-1
        q(1,i)=q(1,i+1);
    end
    carry=0;
    for i=n:-1:1
        sum=xor(xor(a(1,i),c(1,i)),carry);
        carry=or(and(a(1,i),c(1,i)),and(xor(a(1,i),c(1,i)),carry));
        a(1,i)=sum;
    end
    if (a(1,1)==1)
       q(1,n)=0;
       carry=0;
        for i=n:-1:1
        sum=xor(xor(a(1,i),b(1,i)),carry);
        carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),carry));
        a(1,i)=sum;
        end
    else
        q(1,n)=1;
    end
end
fprintf('Remainder =');
disp(a);
fprintf('Quotient=');
disp(q);
end

Computer Organisation & Architecture

PROGRAM IN MATLAB FOR MULTIPLICATION OF TWO UNSIGNED INTEGER BINARY NUMBERS BY PARTIAL-PRODUCT METHOD (4BITS NUMBERS)


function lab2_coa
a=input('enter a:');
b=input('enter b:');
r=[0 0 0 0 0 0 0 0];
c=0;
for j=4:-1:1
    if(b(1,j)==0)
        continue;
    end
    for i=4:-1:1
    sum=xor(xor(r(1,i+j),a(1,i)),c);
    carry=or(and(r(1,i+j),a(1,i)),and(xor(r(1,i+j),a(1,i)),c));
    c=carry;
    r(1,i+j)=sum;
 
    end
 
end

disp(r);
disp(c);

end

Computer Organisation & Architecture

PROGRAM IN MATLAB FOR SUBTRACTION OF TWO UNSIGNED INTEGER BINARY NUMBER (4BITS NUMBERS)


function lab3_coa
a=input('enter a:');
b=input('enter b:');
c=0;
temp=a;
for i=4:-1:1
    if(b(1,i)==1)
        b(1,i)=0;
 
    else
        b(1,i)=1;
    end
end
a=[0 0 0 1];
for i=4:-1:1
sum=xor(xor(a(1,i),b(1,i)),c);
carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),c));
c=carry;
result(1,i)=sum;
end
a=temp;
b=result;
c=0;
for i=4:-1:1
sum=xor(xor(a(1,i),b(1,i)),c);
carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),c));
c=carry;
result(1,i)=sum;
end
if(c==0)
    fprintf('The number is negative.');
    for i=4:-1:1
    if(result(1,i)==1)
        result(1,i)=0;
 
    else
        result(1,i)=1;
    end
    end
a=[0 0 0 1];
for i=4:-1:1
sum=xor(xor(a(1,i),result(1,i)),c);
carry=or(and(a(1,i),result(1,i)),and(xor(a(1,i),result(1,i)),c));
c=carry;
result(1,i)=sum;
end
end
disp(result);
disp(c);

end

Computer Organisation & Architecture

PROGRAM IN MATLAB FOR  ADDITION OF TWO UNSIGNED INTEGER BINARY NUMBER (4-BITS NUMBERS)




function lab0_coa
a=input('enter a:');
b=input('enter b:');
c=input('enter c:');
for i=4:-1:1
sum=xor(xor(a(1,i),b(1,i)),c);
carry=or(and(a(1,i),b(1,i)),and(xor(a(1,i),b(1,i)),c));
c=carry;
result(1,i)=sum;
end
disp(result);
disp(c);
end