Showing posts with label Bitwise Operator. Show all posts
Showing posts with label Bitwise Operator. Show all posts

Number System - Covert a Decimal Number to Octal and Hex Number

Oct 23, 2015

It is  very interesting topic. If we simple think, the process of conversion from decimal number to Octal number, then we can follow the below steps:
1. Let x = 15
2. r[0] = x%8 = 7
3. x = x/8 = 1
4. r[1] = x%8 = 1;
5. x = x/8 = 0
Terminate the algorithm, we find (15)10 = (17)8 [Note: reverse r]
But if we use bit-wise operator, then it makes more interesting and efficient.

Number Conversion -1 : Decimal to Binary

Oct 21, 2015

At first glance, we think about the below algorithm
1. take input x
2. r[i] = x%2;
3. x = x/2
4. do above steps until x =0

the complexity of this algorithm is O(lgn) , where n = decimal number.

Peasant or binary multiplication

Oct 1, 2015

Peasant or binary multiplication has been widely used among those who are unschooled and thus have not memorized the multiplication tables required by long multiplication. The algorithm was also in use in ancient Egypt [Wiki]. :)

Explain:
suppose,
the task is to find the value of 12 x 7

Count Bits of a Number in C

Sep 29, 2015

It is very simple to determine the number of bits of an integer number:
Algorithm:
1. take input x, initialize countbit : = 0
2. check x is zero, yes then go to step 5
3. x: = Shift one bit left of x,countbit:=countbit+1;
4. go to step 2.
5. End