TransWikia.com

Easiest way to convert a char* of hex to actual hex in C?

Stack Overflow Asked by PurpleSpark on December 3, 2021

I have a char* of user input hex digits that I want to convert to actual hex (u8_t type) to be able to be used in an i2c command.

Example:
Input: char* = 55 and I want to be able to use this as 0x55 in my i2c command so it has to be in hex format (My command looks like i2c_write(u8_t addr, blah, blah) so I would use it like i2c_write(0x55, blah, blah). Does anyone know how to change it? I’ve looked at resources online and I can only find how to convert it to an int.

One Answer

Never mind, I figured it out by using strtol(<char array>, NULL, 16)

Answered by PurpleSpark on December 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP