Thank you for this response.
I extend your example function - with checking the first two characters on "0x". I don't know, if this will work anyway but currently it works.
But what I thought, that when I set the octetstring to 0x0 - the string will automatically a hexadecimal value. And I get as result the hexadecimal value - without using a special function - for reformatting. I'm a little confused but it is apperently the solution for my problem.