1
bit extraction in c =================== http://stackoverflow.com/questions/1516301/how-do-i-extract-a-bit-in-a-more- optimal-way int extractBit(char byte, int pos) { assert( (pos >= 0) && (pos < 8) ); -----remove this portion when unsigned return ( ( byte & (1<<pos) ) >> pos); ------- use this return (byte >> pos) & 1; int extractBit(char byte, int pos) { return (byte >> pos) & 0x01; } xor within the byte modulo 2 addition in C http://books.google.com.pk/books? id=adxb8CRx5vQC&pg=PA55&lpg=PA55&dq=modulo+2+addition+in+C&source=bl&o ts=iyrN3Gh-kA&sig=4B9216c8ngyByUzI_xrqGf- VAts&hl=en&redir_esc=y#v=onepage&q=modulo%202%20addition%20in %20C&f=false

Bitwise Manipulations

Embed Size (px)

DESCRIPTION

Bitwise

Citation preview

bit extraction in c===================http://stackoverflow.com/questions/1516301/how-do-i-extract-a-bit-in-a-more-optimal-way

int extractBit(char byte, int pos) { assert( (pos >= 0) && (pos < 8) ); -----remove this portion when unsigned return ( ( byte & (1 pos); ------- use this return (byte >> pos) & 1;

int extractBit(char byte, int pos) { return (byte >> pos) & 0x01;}

xor within the byte

modulo 2 addition in C

http://books.google.com.pk/books?id=adxb8CRx5vQC&pg=PA55&lpg=PA55&dq=modulo+2+addition+in+C&source=bl&ots=iyrN3Gh-kA&sig=4B9216c8ngyByUzI_xrqGf-VAts&hl=en&redir_esc=y#v=onepage&q=modulo%202%20addition%20in%20C&f=false