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; ...

Binary to Hexadecimal Conversion in C

Binary to Hexadecimal Conversion in C

✅ Binary to Hexadecimal Conversion in C

#include<stdio.h>
int main( )
{
    int num, hexa = 0, remainder, j = 1;
    printf("Enter the binary number:\n");
    scanf("%d", &num);
    while(num != 0)
    {
        remainder = num % 10;
        hexa = hexa + remainder * j;
        j = j * 2;
        num = num / 10;
    }
    printf("The hexadecimal value is %X\n", hexa);
}
  

πŸ“˜ Explanation:

This C program converts a binary number (input as an integer) to its hexadecimal equivalent. The binary number is first converted to its decimal form manually using bit-weight multiplication (base 2 logic). The resulting decimal is then printed in hexadecimal using the format specifier %X.

🧾 Sample Output:

Enter the binary number:
1010
The hexadecimal value is A
  

πŸ”‘ Keywords:

Binary to Hexadecimal, C Program for Hex Conversion, base conversion in C, Hexadecimal output, %X format specifier, scanf printf in C

πŸ“Œ Hashtags:

#CProgramming #BinaryToHex #HexadecimalConversion #BaseConversion #PrintfFormat #BeginnerCCode #BitwiseLogic

Comments

Popular Posts

πŸŒ™