/* Function to print binary representation of a number */
void printBinary(int n)
{
int i ;
for (i=31; i>=0; i--)
printf("%d", ((1<<i & n))?1:0) ;
printf("\n") ;
}
/* Function to get 2's complement of a number */
int get2scomplement(int n)
{
int i, k=0 ;
for (i=0; i<32; i++)
k |= ~(1<<i | n) ;
k+=1 ;
return k ;
}
Pages
Labels
01 Knapsack
(1)
Ad Hoc
(1)
Backtracking
(1)
Binary Search Tree
(1)
bits
(1)
Brute Force
(1)
codelib
(2)
Data Structures
(1)
Dijkstra
(1)
DP
(2)
Graphs
(1)
Heaps
(1)
Joseph
(1)
Maximum 1-D Sum
(1)
Maximum Contiguous Sum
(1)
Primes
(1)
Priority Queues
(1)
Recursion
(1)
Sieve of Atkins
(1)
UVaOJ Vol-102
(1)
UVaOJ Vol-109
(1)
UVaOJ Vol-5
(1)
Showing posts with label bits. Show all posts
Showing posts with label bits. Show all posts
Thursday, January 6, 2011
Useful Bit-manipulation Functions
Subscribe to:
Posts (Atom)