#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;
    printf("Enter a digit (1 to 4): \n");
    scanf("%d", &userInput);

    if (userInput >= 1 && userInput <= 4) {
        printf("Hex values from digit %d to 1: ", userInput);
        
        for (int i = userInput; i >= 1; i--) {
            int shiftAmount = (i - 1) * 4;
            int digit = (val >> shiftAmount) & 0xF;
            printf("%X ", digit);
        }
        printf("\n");
    } 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: