Printing out byte array as formatted text gives different outputs - C -


i trying print out byte array 1 byte @ time in hexadecimal format within loop this:

int my_function(void *data) {    obuf = (str*)data;     int i;    (i = 0; < obuf->len; i++)    {       printf("%02x:", obuf->s[i]);    }     return 0; } 

str in case structure kamailio - review @ http://www.asipto.com/pub/kamailio-devel-guide/#c05str

the expected output:

80:70:0f:80:00:00:96:00:1d:54:7d:7c:36:9d:1b:9a:20:bf:f9:68:e8:e8:e8:f8:68:98:e8:ee:e8:b4:7c:3c:34:74:74:64:74:69:2c:5a:3a:3a:3a:3a:3a:3a:32:24:43:ad:19:1d:1d:1d:1d:13:1d:1b:3b:60:ab:ab:ab:ab:ab:0a:ba:ba:ba:ba:b0:ab:ab:ab:ab:ab:0a:ba:ba:ba:ba:b9:3b:61:88:43: 

what getting:

ffffff80:70:0f:ffffff80:00:00:ffffff96:00:1d:54:7d:7c:36:ffffff9d:1b:ffffff9a:20:ffffffbf:fffffff9:68:ffffffe8:ffffffe8:ffffffe8:fffffff8:68:ffffff98:ffffffe8:ffffffee:ffffffe8:ffffffb4:7c:3c:34:74:74:64:74:69:2c:5a:3a:3a:3a:3a:3a:3a:32:24:43:ffffffad:19:1d:1d:1d:1d:13:1d:1b:3b:60:ffffffab:ffffffab:ffffffab:ffffffab:ffffffab:0a:ffffffba:ffffffba:ffffffba:ffffffba:ffffffb0:ffffffab:ffffffab:ffffffab:ffffffab:ffffffab:0a:ffffffba:ffffffba:ffffffba:ffffffba:ffffffb9:3b:61:ffffff88:43: 

could please me understand why there of bytes prefixed ffffff , other aren't?

thanks in advance

looks obuf->s[i] returns signed value

you need cast unsigned value rid of fff.. @ start.

printf("%02x:", (unsigned char)(obuf->s[i])); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -