# Show value by HEX format

663 views

Hi,

I meet a troube for show value by HEX format in my project, the result is strange as my meaning. I explain as follows.

I create a "Views::Text" and use a "Method" to assign a HEX format string. I test by "Prototyper(F5)" and result is normal.

But if I test on real machine then result is abnormal, the OSD is always keep show "0000" after I adjusted value. (Value of OSD is no any change. but real value is changed by "trace")

I don't know why the result is difference, has any limitation for this request? I made a simple sample as following link.

In this sample, you can press plus/minus key for add/dec value and value change by HEX format. But due you have not real machine, so you will always get normal result.

Could you help me to analysis this trouble? And have other ways for show value by HEX format?

PS: My developing platform is "Panasonic.PH1sLD3_Linux_OpenGL.RGBA8888", Version of Embeddid Wizard is 6.10.

Hi Steward,

thank you for your question and the good preparation of the sample. I think your question addresses two aspects:

1.) How to convert a decimal value into a string with hexadecimal digits?

The following code snippet contains the implementation of a method DecValue2HexString( int32 aValue, int32 aNumberOfDigits):

```var string str  = "";
var string sign = "";
var int32  num  = aValue;

/* take care on negative values */
if ( num < 0 )
{
sign = "-";
num = -num;
}

/* limit given number of digits */
if (( aNoOfDigits <= 0 ) || ( aNoOfDigits > 8 ))
aNoOfDigits = 1;

/* convert one digit after the other */
while (( num > 0 ) || ( aNoOfDigits > 0 ))
{
var int8 digit = (int8)( num % 16 );

/* convert digit into character '0'-'9' or 'A'-'F' */
if ( digit < 10 )
str = (char)((int8)'0' + digit ) + str;
else
str = (char)((int8)'A' + digit - 10 ) + str;

/* process next digit */
num = num / 16;
aNoOfDigits = aNoOfDigits - 1;
}

/* add sign and return result */
return sign + str;
```

2. Why do you receive only '0000' on the target?

Probably you read your values from a data class (device class) which is accessed as autoobject. If you do not have a variable that refers to the autoobject all the time, it will be deleted by the Garbage Collector and re-created when you access it next time. For more details, please have a look to the article 'Data stored in an autoobject get lost'.

I understood and result is well in my project.

Many thanks.