Exforsys

Online Training

hex data formatting

This is a discussion on hex data formatting within the C and C++ forums, part of the Programming Talk category; In our application header and trailor to be added to message and sent of fixed length. The header and trailor ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2006, 01:05 PM
Junior Member
 
Join Date: Jun 2005
Posts: 1
subathira is on a distinguished road
hex data formatting

In our application header and trailor to be added to message and sent of fixed length. The header and trailor are to be sent as hex constant values. The message they read it as ascii.


Tried formatting by assigning hex values to char array.but
it is not properly interpreted on other end. In addition null gets added to length and they receive one byte addition to expected
length and error out.But when do strlen(buffer) this shows the right length
please provide how this can be done avoiding the addition of null at End of string ..can this be done with memcpy...tried byt getting different values..

we have the struct defining the message fields

{
char MesgLen [3]; //2 bytes
char Reserve[3] // 2bytes
.
.
.

Data[23] //22 bytes
..
trailor [3] // 2bytes
}

In my program as anandt specified have populated the fields with char array

like MesgLen[0]=0x00;
MesgLen[1]=0xE7;
and so on....
we are to sent the message of 28 bytes length..expected out on other end
00E70002AB.....Data.....1C1A The header and trailor have to be hex .Most of the fields gets populated properly...but now the output on other end becomes
20202000.......data...1C1A00

Regarding the mesg length expected number of bytes on other end was 28 bytes but they receive 29 bytes.On my mesg above u can se at the end 00-representing null field.when i get bufferlen on my side it is 28 but i think because of string format null gets added.
Can anything be done to avoid the above problem with memcpy..or any other suggestions ....hope i am clear...please help me with valuble suggestions

Last edited by subathira; 02-18-2006 at 07:41 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-11-2006, 01:13 AM
Junior Member
 
Join Date: Mar 2006
Posts: 1
Arun123 is on a distinguished road
Here is something you can try

strings are defined as an array of characters or a pointer to a portion of memory containing ASCII characters. A string in C is a sequence of zero or more characters followed by a NULL ()character:

The strncat(), strncmp,() and strncpy() copy functions are string restricted version of their more general counterparts. They perform a similar task but only up to the first n characters. Note the the NULL terminated requirement may get violated when using these functions, for example:


char *str1 = "HELLO WELCOME";
char *str2;
int length = 2;


(void) strcpy(str2,str1, length); /* str2 = "HE" */

str2 is NOT NULL TERMINATED!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-28-2006, 08:10 PM
Member
 
Join Date: Apr 2006
Posts: 65
priyaraji is on a distinguished road
Hi,
In the character array, You chcek for '/0' and then print the output until it is reached. Once the '/0' is reached skip from printing.This will solve your problem.

Sripriya
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.