Tuesday, 26 July 2016

Bit flags, Bit masks and why they are useful?

Bit flags, Bit masks and why they are useful? Explanation with examples.


First of all we want to know what bit flag is and what is bit mask, in this post I would like to give brief knowledge on bit flags and bit masks

Bit Flags: As of we know that we cannot access bits directly, So we have to use the bit-wise operators to set, unset, or query them.

Bit flags are the individual bits that are used to improve the efficiency of the storage.

In storage-intensive cases where we have lots of related Boolean options, it can be useful to “pack” 8 individual Boolean's into a single byte for storage efficiency purposes.

Why are bit flags useful?

Bit flags are used in two cases:

1) It is very much useful when you have many sets of identical bit flags.

Sunday, 24 July 2016

Diff in Conversion ctr and explicit ctr

Diff in Conversion ctr and explicit ctr, explain with examples:


Before going to know about the difference between the implicit and explicit convertions we need to have a little bit knowledge on casting

Casting


Casting means converting form one data type to another. We have two types of castings
·        Implicit casting
·        Explicit casting


Implicit casting


The Implicit casting doesn't require any casting operator. This casting is normally used when converting data from smaller integral types to larger or derived types to the base type.

Thursday, 21 July 2016

Explain hash_map and bucketing with examples


A small introduction to the hash map:

The template class describes an object that controls a varying-length sequence of elements that has bidirectional access. You use the container hash_map to manage a sequence of elements as a hash table, each table entry storing a bidirectional linked list of nodes, and each node storing one element.

Syntax of the hash map is:
Microsoft::VisualC::StlClr::GenericPair

Here the parameters are explained as shown below. Key - The type of the key component of an element in the controlled sequence.Mapped- The type of the additional component of an element in the controlled sequence.

In the above syntax an element consists of a key, for ordering the sequence, and a mapped value, which goes along for the ride.

Tuesday, 19 July 2016

Bit Count In Product

Bit Count In Product. Explain with examples:

Write a function:
int solution(int A, int B);
that, given two non-negative integers A and B, returns the number of bits set to 1 in the binary representation of the number A * B.
For example, given A = 3 and B = 7 the function should return 3, because the binary representation of A * B = 3 * 7 = 21 is 10101 and it contains three bits set to 1.
Assume that:
·   A and B are integers within the range [0..100,000,000].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Finding the length of the Arrays

How to find the length of the Array, explain with examples:

A non-empty zero-indexed array A consisting of N integers is given.
Array A represents a linked list. A list is constructed from this array as follows:

• the first node (the head) is located at index 0;
• the value of a node located at index K is A[K];
• the successor of a node located at index K is located at index A[K];
• if the value of a node is −1 then it is the last node of the list. For example, for array A such that: A[0] = 1
A[1] = 4
A[2] = -1
A[3] = 3
A[4] = 2
the following list is constructed:
• the first node (the head) is located at index 0 and has a value of 1;
• the second node is located at index 1 and has a value of 4;
• the third node is located at index 4 and has a value of 2;
• the fourth node is located at index 2 and has a value of −1.