BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Display Buffer data as ascii charaters

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Maurice Anderson
Guest





PostPosted: Mon Apr 23, 2007 8:10 am    Post subject: Display Buffer data as ascii charaters Reply with quote



I have a buffer defined as BYTE *buffer. In the buffer is a series of
binary data listed in asci format. The data in buffer is FFD8FFE13F.

If I do this:

HexChar = buffer[0];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData =+ wData;

HexChar = buffer[1];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData will display 'FFD8, the first 2 bytes in buffer'.

My question, how can I put the entire ascii data into wData for display
without iterating through each character as I did above?

Thanks
Back to top
Dennis Jones
Guest





PostPosted: Mon Apr 23, 2007 8:10 am    Post subject: Re: Display Buffer data as ascii charaters Reply with quote



"Maurice Anderson" <mauriceanderson (AT) hotmail (DOT) com> wrote in message
news:462c2f8a$1 (AT) newsgroups (DOT) borland.com...
Quote:
I have a buffer defined as BYTE *buffer. In the buffer is a series of
binary data listed in asci format. The data in buffer is FFD8FFE13F.

If I do this:

HexChar = buffer[0];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData =+ wData;

HexChar = buffer[1];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData will display 'FFD8, the first 2 bytes in buffer'.

My question, how can I put the entire ascii data into wData for display
without iterating through each character as I did above?

As I thought about your question again, I realized that what you probably
want is the function BinToHex. Its prototype is declared in classes.hpp.
Try this (rough example):

#include <classes.hpp>

BYTE buffer[5] = "\xFF\xD8\xFF\xE1\x3F";
char output[sizeof(buffer)*2+1];
memset( output, 0, sizeof(output) );
BinToHex( buffer, output, sizeof(buffer) );


....after which 'output' will contain the text: "FFD8FFE13F" followed by a
trailing null terminator.

- Dennis
Back to top
Dennis Jones
Guest





PostPosted: Mon Apr 23, 2007 8:10 am    Post subject: Re: Display Buffer data as ascii charaters Reply with quote



"Maurice Anderson" <mauriceanderson (AT) hotmail (DOT) com> wrote in message
news:462c2f8a$1 (AT) newsgroups (DOT) borland.com...
Quote:
I have a buffer defined as BYTE *buffer. In the buffer is a series of
binary data listed in asci format. The data in buffer is FFD8FFE13F.

If I do this:

HexChar = buffer[0];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData =+ wData;

HexChar = buffer[1];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData will display 'FFD8, the first 2 bytes in buffer'.

My question, how can I put the entire ascii data into wData for display
without iterating through each character as I did above?

Your question is unclear, the code you've supplied does not compile, and the
purpose of the code is not stated. Is 'FFD8FFE13F' a text string, or the
hexadecimal representation of binary data? What are the data types for
HexChar and wData? Please provide 'real' code that compiles and executes,
and then explain what you want your code to do. Then maybe someone can
answer your question.

- Dennis
Back to top
Maurice Anderson
Guest





PostPosted: Mon Apr 23, 2007 8:10 am    Post subject: Re: Display Buffer data as ascii charaters Reply with quote

Quote:
Is 'FFD8FFE13F' a text string, or the hexadecimal representation of binary
data?

It is a hexadecimal representation of binary data.

Quote:
HexChar and wData?

String HexChar
WideString wData.

-M-

"Dennis Jones" <nospam (AT) nospam (DOT) com> wrote in message
news:462c3743$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Maurice Anderson" <mauriceanderson (AT) hotmail (DOT) com> wrote in message
news:462c2f8a$1 (AT) newsgroups (DOT) borland.com...
I have a buffer defined as BYTE *buffer. In the buffer is a series of
binary data listed in asci format. The data in buffer is FFD8FFE13F.

If I do this:

HexChar = buffer[0];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData =+ wData;

HexChar = buffer[1];
wData = wData + HexChar.IntToHex(HexChar.ToInt(), 2);

wData will display 'FFD8, the first 2 bytes in buffer'.

My question, how can I put the entire ascii data into wData for display
without iterating through each character as I did above?

Your question is unclear, the code you've supplied does not compile, and
the purpose of the code is not stated. Is 'FFD8FFE13F' a text string, or
the hexadecimal representation of binary data? What are the data types
for HexChar and wData? Please provide 'real' code that compiles and
executes, and then explain what you want your code to do. Then maybe
someone can answer your question.

- Dennis
Back to top
Maurice Anderson
Guest





PostPosted: Mon Apr 23, 2007 8:40 pm    Post subject: Re: Display Buffer data as ascii charaters Reply with quote

Quote:
BYTE buffer[5] = "\xFF\xD8\xFF\xE1\x3F";
char output[sizeof(buffer)*2+1];
memset( output, 0, sizeof(output) );
BinToHex( buffer, output, sizeof(buffer) );



Hey, thanks! It worked! But it seems it wont work for large binary data >
1.5 megs.
Back to top
Dennis Jones
Guest





PostPosted: Mon Apr 23, 2007 8:51 pm    Post subject: Re: Display Buffer data as ascii charaters Reply with quote

"Maurice Anderson" <mauriceanderson (AT) hotmail (DOT) com> wrote in message
news:462cd382$1 (AT) newsgroups (DOT) borland.com...
Quote:
BYTE buffer[5] = "\xFF\xD8\xFF\xE1\x3F";
char output[sizeof(buffer)*2+1];
memset( output, 0, sizeof(output) );
BinToHex( buffer, output, sizeof(buffer) );



Hey, thanks! It worked! But it seems it wont work for large binary data
1.5 megs.

Does it give an error? I don't know what its limitations are, but you can
always iterate through the data in chunks, in whatever size is appropriate
for the data.

- Dennis
Back to top
Maurice Anderson
Guest





PostPosted: Tue Apr 24, 2007 7:32 am    Post subject: Re: Display Buffer data as ascii charaters Reply with quote

Quote:
but you can always iterate through the data in chunks, in whatever size is
appropriate for the data.

How would I do that? I thought it was only 1 byte at a time.
Back to top
Dennis Jones
Guest





PostPosted: Tue Apr 24, 2007 8:10 am    Post subject: Re: Display Buffer data as ascii charaters Reply with quote

"Maurice Anderson" <mauriceanderson (AT) hotmail (DOT) com> wrote in message
news:462d6c4d$1 (AT) newsgroups (DOT) borland.com...
Quote:
but you can always iterate through the data in chunks, in whatever size
is appropriate for the data.

How would I do that? I thought it was only 1 byte at a time.

Oh no, look at my example again. It converts all 5 bytes at once. If you
wanted to do it in chunks, you just move the pointer by some number of bytes
at a time. For example, if the data was 1000 bytes, but you wanted to
convert 10 bytes at a time, you could do this:

#include <classes.hpp>

BYTE buffer[1000] = "\xFF\xD8\xFF\xE1\x3F...";
char output[sizeof(buffer)*2+1];
memset( output, 0, sizeof(output) );
const int chunksize=10;
for ( char* inp = buffer, outp = output;
inp < buffer+sizeof(buffer);
inp += chunksize, outp += (chunksize*2) )
{
BinToHex( inp, outp, chunksize );
}

Note, however, that this is just example code...it is *not* intended to be
safe for real-world use! For instance, it will result in a buffer overrun
if the size of the source buffer is not an even multiple of chunksize (e.g.
if buffer size is 100 and chunk size is 30, it would attempt to read 30
bytes 4 times, resulting in reading and converting 120 bytes -- 20 bytes
more than actually exist). If you have a situation where the sizes are
unknown, you must factor that into your operation.

- Dennis
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.