Search for an XML Node using libxml2 in C

XML is widely used format to store or transmit data over internet. Here we’ll see how to search for an XML node in a file. We’ll use this XML file as an example. Search XML Node by its Name First we’ll see how to search a node based on its name. In the above example … Continue reading “Search for an XML Node using libxml2 in C”

Delete an XML Node using libxml2 in C

In the previous article we saw how to add a new XML node. Here we’ll see how to delete an an XML node from a file. We’ll use the same example XML file. In this example, we have 3 ‘book‘ nodes under ‘catalog‘. We’ll write a C program to delete one of them. Program to … Continue reading “Delete an XML Node using libxml2 in C”

Add New Node to XML File Using libxml2 in C

In the previous article, we saw how to parse an XML file. Here we’ll see how to add new node to XML file using C programming language. Here also we’ll use libxml2 parser. We’ll use this XML file as an example. Here we have 3 book nodes under the catalog node. We’ll add one more … Continue reading “Add New Node to XML File Using libxml2 in C”

Count Set Bits of a Number in C

A number consists of multiple bits in its binary representation. For example, an integer would have 32 bits and a long would have 64 bits on 64-bit system. Bit values could either be 0 (not set) or 1 (set). From the diagram above, we can see that the binary representation of 2392 has 5 set … Continue reading “Count Set Bits of a Number in C”

Brian Kernighan’s Algorithm to Count the Set Bits of a Number

To count all set bits of a number, we can loop through all the bits and check whether any bit is set. For example, an integer has 32 bits. We can check all 32 bits in a loop to count the set (1) bits. Here will see how we can improve this mechanism using Brian … Continue reading “Brian Kernighan’s Algorithm to Count the Set Bits of a Number”

0
1
0
1
4
0