Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

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

πŸŒ™