Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

C Program to Convert Hexadecimal to Binary

C Program to Convert Hexadecimal to Binary

✅ C Program to Convert Hexadecimal to Binary (Using Bitwise Operators)

#include <stdio.h>
int main() {
    int num;
    printf("Enter a hexadecimal number: ");
    scanf("%x", &num);   // read hex directly into int

    printf("Binary: ");
    for (int i = 31; i >= 0; i--) {
        int bit = (num >> i) & 1;
        printf("%d", bit);
    }
    printf("\n");
    return 0;
}
  

๐Ÿ“˜ Explanation:

This program converts a hexadecimal number into its binary form using bitwise operators.

  • scanf("%x", &num) → directly reads a hexadecimal number into an integer.
  • (num >> i) & 1 → extracts the i-th bit from the number.
  • Loop runs from bit 31 to 0 → prints all 32 bits (full binary representation).
  • Output shows the binary form padded to 32 bits.

๐Ÿงพ Sample Output:

Enter a hexadecimal number: 1A
Binary: 00000000000000000000000000011010

Enter a hexadecimal number: FF
Binary: 00000000000000000000000011111111
  

๐Ÿ”‘ Keywords:

C program hex to binary, hexadecimal to binary conversion, bitwise operators in C, scanf %x example, binary representation in C

๐Ÿ“Œ Hashtags:

#CProgramming #HexToBinary #BitwiseOperators #CodingForBeginners #InterviewQuestions

๐Ÿ” Search Description:

This C program converts hexadecimal to binary using bitwise operators. It reads hex with %x and prints the 32-bit binary representation.

Comments

๐ŸŒ™