Chapter - 15: Operations On Bits

An animal could be either a canine (dog, wolf, fox, etc.), a feline (cat, lynx, jaguar, etc.), a cetacean (whale, narwhal, etc.) or a marsupial (koala, wombat, etc.). The information whether a particular animal is canine, feline, cetacean, or marsupial is stored in bit number 0, 1, 2 and 3 respectively of a integer variable called type. Bit number 4 of the variable type stores the information about whether the animal is Carnivore or Herbivore. For the following animal, complete the program to determine whether the animal is a herbivore or a carnivore. Also determine whether the animal is a canine, feline, cetacean or a marsupial.

struct animal
 char name[30] ;
 int type ;
struct animal a = { "OCELOT", 18 } ; 

18 = (10010)binary

here last four bits represent the type of the animal so and first represent its nutrition method.

0th bit = canine
1st bit = feline
2nd bit = cetacean
3rd bit = marsupial
4th bit = Herbivorous or carnivorous.

This is an "herbivorous" animal of "feline" family. 

© 2021 Garbage Valuegarbage value logo