For this project I use Python’s colorsys to convert RGB to HSV vice versa to be able to manipulate saturation and lightness, but I noticed that some colors yields bogus results.
For example, if I take any primary colors there’s no problem:

However if I chose a random RGB color and convert it to HSV, I sometime gets bogus results.
Sometimes these bogus results occurs when I increase or decrease the lightness or the saturation of a color.
In this example lightness 10%, 20% and saturation 100% are bogus:

I’m not quite sure why it happens nor how I should fix this ..
The problem is in your dec2hex code:
When your value is less than 16, you’re duplicating it to get the value, in other words, multiplying it by 17. You want this: