Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

Popular Posts

πŸŒ™