9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia07/ex12.c (525B)
   1 #include <stdio.h>
   2 
   3 #define MASK_BIT 0x01
   4 
   5 typedef unsigned char uchar;
   6 
   7 uchar set_bit(uchar byte, short linea);
   8 uchar clear_bit(uchar byte, short linea);
   9 
  10 int main (void)
  11 {
  12     uchar byte = 0x81; /* 1000 0001 */
  13 
  14     printf("0x%X\n", byte);
  15 
  16     byte = set_bit(byte, 3);
  17 
  18     printf("0x%X\n", byte);
  19 
  20     byte = clear_bit(byte, 3);
  21 
  22     printf("0x%X\n", byte);
  23 
  24     return 0;
  25 }
  26 
  27 uchar set_bit(uchar byte, short linea)
  28 {
  29     return (byte | (MASK_BIT << linea));
  30 }
  31 
  32 uchar clear_bit(uchar byte, short linea)
  33 {
  34     return (byte & ~(MASK_BIT << linea));
  35 }