0

I'm trying to create a proof-of-concept beginner program that will essentially do this: http://www.asciitohex.com/

However everything I've found on google is for turning numbers into hex, not ASCII. So what is the simplest and most direct way to turn any input text into its hex form? Will I have to assign each letter that goes cin a hex value and substitute fir what comes cout?

  • CS 51 by Malan is a great course online (free) and will teach you how to read the character arrays... though they're all just ints, but he explains why etc.. – Stephen J Jul 04 '13 at 03:48

1 Answers1

0

http://www.cplusplus.com/reference/cstdlib/strtol/

Strtol will parse the hex number you're given; you can specify the base (and it will even handle the 0x prefix that comes before some hexadecimal numbers). Just store the string from cin, give it the relevant parameters, and boom, you're done.

If you want to output the number as a hexadecimal, you can change the base of the output stream cout to hex, using http://www.cplusplus.com/reference/ios/hex/ (passing in cout as your parameter).

algorowara
  • 1,700
  • 1
  • 15
  • 15