Sunday, September 30, 2018

Android: Change color of the downloaded material icon

No comments:
Add below two lines in your ImageButton or ImageView


Check the example shown below:

Tuesday, September 11, 2018

Android Studio: Change Toolbar font

No comments:
Step 1: Click the link below and follow the steps used to use a custom font in your project. Refer:

Step 2 : Define Toolbar Theme
Open res/values/styles.xml define the following 
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
    <item name="android:fontFamily">@font/roboto_condensed_bold</item>

Step 3: Add the following to your toolbar layout

Run the app... 

Android Studio: How to use custom font in an Android project

No comments:
Step 1: Right-click the res folder and go to New > Android Resource Directory.

Step 2: From Resource type list, select font, and then click OK.

Step 3: Copy your font files (.ttf) and paste it in the font directory created in Step 2. (file name of the fonts should must contain only lowercase a-z, 0-9, or underscore)

Step 4: Now you can assign your font in the xml file using @font/font_name

Saturday, August 25, 2018

Create a Navigation Drawer using Android Studio with Kotlin Support

No comments:
Refer to the link below. The page shows you how to implement a navigation drawer using Drawer Layout.

Sunday, April 15, 2018

GATE-Computer Networks-Flow Control

No comments:

Previous GATE questions with solutions on Computer Networks (Flow Control) - CS/IT

GATE -2015
1. Since it is a network that uses switch, every packet goes through two links, one from source to switch and other from switch to destination.
Since there are 10000 bits and packet size is 5000, two packets are sent. Transmission time for each packet is 5000 / 107 seconds
Two hosts are connected via a packet switch with 107 bits per second links. Each link has a propagation delay of 20 microseconds. The switch begins forwarding a packet 35 microseconds after it receives the same. If 10000 bits of data are to be transmitted between the two hosts using a packet size of 5000 bits, the time elapsed between the transmission of the first bit of data and the reception of the last bit of the data in microseconds is _________.
(a) 1075      (b) 1575        (c) 2220         (d) 2200

Ans: option (b)
It is given that there are 10,000 bits and since the packet size id 5000 it means we have 2 packets to send. 
Transmission time for one packet = 5000 / 107 seconds = 500μs
Transmission time is the time taken to transmit a packet from host to the outgoing link.

It is also given that the propagation delay of links is 20μs.  Propagation delay is the time taken by a bit to reach from sender to receiver (in this case from sender to switch it is 20μs and from switch to receiver it 20μs)

Time for the first packet (P1) to reach switch =Transmission time + Propagation delay
=500μs + 20μs = 520μs
Once P1 reaches the switch, the switch will take 35μs to process the packet and then it takes 500μs to transmit it to the link and then the packet will take 20μs to reach the receiver.
Therefore Time taken by P1 to reach from switch to receiver = 35μs + 500μs+ 20μs = 555μs
Therefore time taken by P1 to reach from sender to receiver = 520μs+555μs = 1075μs

But we need to note that after 520μs the switch starts receiving second packet (P2).
i.e. At 520μs+500μs = 1020μs P2 is completely received by switch.
Now Time taken by P2 to reach from switch to receiver = 35μs + 500μs+ 20μs = 555μs
It means that at  1575μs (1020μs+555μs) P2 reaches the destination.

2. Suppose that the stop-and-wait protocol is used on a link with a bit rate of 64 kilobits per second and 20 milliseconds propagation delay. Assume that the transmission time for the acknowledgement and the processing time at nodes are negligible. Then the minimum frame size in bytes to achieve a link utilization of at least 50% is_________________.
(a) 160      (b) 320      (c) 640      (d) 220      

Ans: option (b)
Since the link utilization should be atleast 50% it means that efficiency, η 50%
Since it is mentioned that it is a stop&wait protocol, the efficiency of the link can be calculated as below:
η =  1 /( 1 + 2a)
a = Tp/Tt (where Tp = Propagation delay & Tt = Transmission Time)
Lets see the length of the packet to achieve a link utilization of 50%
50/100 = 1 /( 1 + 2a)
1/2 = 1 /( 1 + 2a)
a = 1/2
Tp/Tt = 1/2
Tt = 40ms
Tt = transmission time = L/B (where L = length of packet and B = bandwidth)
L/B = 40
L =40 * B = 40 ms * 64 Kbps = 40*10-3 *64*103 = 2560 bits
Since we need to determine the frame size in bytes L = 2560/8 = 320 bytes.
Therefore, the minimum frame size in bytes to achieve a link utilization of at least 50% is 320bytes

Saturday, March 31, 2018

ISRO Questions - C/C++ Programming

No comments:
Recruitment Entrance Test for Scientist/Engineer
Previously asked questions on C/C++ Programming

ISRO May 2017
1. What is the output of this C++ program?
#include <iostream>
using namespace std;
void square (int *x)
    *x = (*x)++ * (*x);
void square (int *x, int *y)
    *x = (*x) * --(*y);

int main ( )
    int number = 30;
    square(&number, &number);
    cout << number;
    return 0;

(a) 910    (b) 920     (c) 870     (d) 900

Ans: option (c)
Starting from main function. number variable has been initialized to 30. We pass address of number as parameters in the square function. As per the concept of function overloading in C++ the second square function will be executed. 
--(*y) will be executed first since decrement operator has the higher precedence than multiplication. 
*x = (*x) * --(*y);
*x = 30 * 29;
*x = 870

x is a pointer variable and it holds the address of the variable number. Therefore the value of 870 is now stored to number after the execution of *x = (*x) * --(*y); expression. Hence 870 will be printed.

Other points:
  1. iostream is a header file. Header files are included in C/C++ because they have some inbuilt predefined functions. 
  2. Purpose of using namespace std; - When you make a call to using namespace <some_namespace>; all symbols in that namespace will become visible without adding the namespace prefix. If you do not add that statement you need to call cout << number; like this std::cout << number; else you get the error 'cout' was not declared in this scope.
  3. Function overloading is a feature in C++ where two or more functions can have the same name but different parameters. Difference in parameters can be in terms of number of parameters as we saw in the case of square function or difference can be in terms of data type also. For example refer: