Hello, I’m new to this forum and fairly new to programming. I have a hexadecimal number that I wish to put into a buffer so I can display the 2 least significant bits, that is the two last digits. i.e the number look like this unsigned short = 0xFE18 but I’d like to display on the screen just “18”. Which is the best way to do this? Thanks you so very much! /Pamela
Welcome to G4EF, Pamela Don't know, if this is the best, bu you can do it this way: (1) Print the hex number to a string: Code: sprintf(MyString, "%x", 0xFE18); (2) Print the last two chars of the string : Code: printf("%s\n", MyString+(strlen(MyString)-2)); Complete test program: Code: #include <cstdio> #include <cstring> int main() { char MyString[10]; sprintf(MyString, "%x", 0xFE18); printf("%s\n", MyString+(strlen(MyString)-2)); return 0; }