text: Extract ' k ' bits from a given position in a number . | C program to extract k bits from a given position . ; Function to extract k bits from p position and returns the extracted value as integer ; Driver code
code: #include <stdio.h> NEW_LINE int bitExtracted ( int number , int k , int p ) { return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; } int main ( ) { int number = 171 , k = 5 , p = 2 ; printf ( " The ▁ extracted ▁ number ▁ is ▁ % d " , bitExtracted ( number , k , p ) ) ; return 0 ; }