2 years ago

#45913

test-img

user216905

C++ Convert to hex and store the result in uint8_t


    std::stringstream sstream;
    uint8_t data[1] = { };
    int x =1;
    sstream << "0x" << std::hex << x; //sstream = 0x04b35cc8 "0x1" why the sstream not be only "0x1"    
    uint8_t result= (uint8_t)sstream.str().c_str();// result= 80 
    data[0] = { result};

the function that I want to implement do:

1- convert to hex. For example 1 converted to 0x01 ( Is there another way rather than using stringstream)

2- store the result in uint8_t variable in order to assign it to data[0]

c++

integer

hex

stringstream

uint8t

0 Answers

Your Answer

Accepted video resources