integerToHex wrongly converting negative integers

Project: 
Gurux.DLMS.Python

integerToHex method of _GXCommon.py is wrongly converting negative integers to hex. For instance, -4 should be converted to FC, however it is converting it to X4. This is happening due to str_ = hex(value)[2:] line, as hex(-4) is '-0x4'.

Status: 
Active
Priority: 
Normal
Category: 
Bug report
Component: 
Code
Reporter: 
zmiguel
Created: 
Mon, 06/17/2019 - 23:22
Updated: 
Mon, 06/17/2019 - 23:22

Comments

Kurumi's picture

Hi,

This is verified and you are right. hex -method is Python standard method:
https://docs.python.org/3/library/functions.html#hex

We make own implementation from this. We'll update a new version on next week.

BR,
Mikko

Hi,

You can find a working example here:
https://gist.github.com/i96751414/b1ed2aef2cb9f602d03c305e22cb6e13

It takes into account negative numbers.

Also, just noticed that method integerString might be wrong for negative numbers. Please have a look at the implementation in the above gist.