Emulate Fortran Function Btest In C Language

Emulate the fortran function btest in C language
BTEST function is as part of Bit Functions library in Fortran,
description of BTEST function

btest( m, i ) Tests bit i in m; returns .true. if the bit is 1, and .false. if it is 0.
Here is C language code implementation of BTEST function, which checks for bit and returns true ie 1 if bit is SET or else returns 0.

int btest(int word, int bit)
  unsigned int mask;

  /* Create the bit mask */
  mask = 0x0000001 << bit;

  /* Return TRUE or FALSE*/
  return (( word & mask ) != 0);
Number of View :7730

Tags: , ,

  1. No comments yet.

Content Protected Using Blog Protector By: PcDrome.