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() { ...

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

πŸŒ™