For conversion from hex to binary, simply string together the bits for each hex digit. For instance, 0x509d7a is binary 10100001001110101111010. To wit:
To convert the other way, break the binary number into groups of four, then replace each one with its hex digit. Group the digits starting from the right. If you don't have a complete group of four when you reach the left, pad with zero bits on the left to fill the last group. For instance, binary 111011011111110001 is 0x3b7f1:
Because this conversion is so easy, the easiest way to convert between binary and decimal is usually to go through hex. It generally requires fewer operations, and hex numbers are easier to work with because they are shorter Also, it's easier to remember where you are when scanning a hex number, since the digits differ more.