#include <stdio.h>

#if 0
int main() {
    int val = 0xA54B;//by default its uint16_t!!

    // Extract individual digits
    
    int digit1 = val & 0x000F; // so it takes only F bit and extract that data
    int digit2 = (val & 0x00F0) >> 4;// takes 4 value but push it to last 000F like value 4
    int digit3 = (val & 0x0F00) >> 8;
    int digit4 = (val & 0xF000) >> 12;

    // Print the values
    printf("Digit 1: %X\n", digit1);//B
    printf("Digit 2: %X\n", digit2);//4
    printf("Digit 3: %X\n", digit3);
    printf("Digit 4: %X\n", digit4);//A

    return 0;
}
#endif

#include <stdio.h>

int main() {
    int val = 0xA54B; // Assuming 16-bit integer

    // User input to specify which digit to extract (1 to 4)
    int userInput = 2;
    printf("Enter a digit (1 to 4): ");
    scanf("%d", &userInput);

    if (userInput >= 1 && userInput <= 4) {
        int shiftAmount = (userInput - 1) * 4;
        int digit = (val >> shiftAmount) & 0xF;
        printf("Digit %d: %X\n", userInput, digit);
    } else {
        printf("Invalid input. Please enter a digit between 1 and 4.\n");
        return 1; // Exit with an error code
    }

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: