code_junkie

How do I convert a 12-bit integer to a hexadecimal string in C#?

Nov 11th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. 2748.ToString("X")
  2.  
  3. 2748.ToString("X")
  4.  
  5. char hexCharacters[17] = "0123456789ABCDEF";
  6. void toHex(char * outputString, long input)
  7. {
  8. outputString[0] = hexCharacters[(input >> 8) & 0x0F];
  9. outputString[1] = hexCharacters[(input >> 4) & 0x0F];
  10. outputString[2] = hexCharacters[input & 0x0F];
  11. }
  12.  
  13. i.ToString("X3")
  14.  
  15. (i % 0x1000).ToString("X3")
Add Comment
Please, Sign In to add comment