470,826 Members | 2,020 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

URGENT: DEC / HEX conversion to ASCII code...

heeeeeeeeeeeeeeeeeelpp !!!

Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ???? I'm on
a project of programming a PLC devices. I need to send the ENQ ascii value
together with others data in a string into the plc. I'm also new in VC++ as
well as plc...

Thanks for the advice in advanced.

Rgds,
Joshua Siew
May 25 '06 #1
7 1591

joshua siew wrote:
heeeeeeeeeeeeeeeeeelpp !!!

Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ???? I'm on
a project of programming a PLC devices. I need to send the ENQ ascii value
together with others data in a string into the plc. I'm also new in VC++ as
well as plc...

Thanks for the advice in advanced.

Rgds,
Joshua Siew


mystring[somewhere] = 5;

or perhaps clearer:

#define ENQ 0x5
....
mystring[somewhere] = ENQ;

Chris

May 25 '06 #2
chris,
thanks for the reply but according to BASIC sample program it looks like
this....
....
....
ENQ$ = CHR$(5)
....
....
OPEN "COM1":"AS#1"
SENDATA$="00FFTT204ABCD34"
PRINT #1, ENQ$;SENDATA$
....
....

I just want to translate this to MS VC++. Any idea ?

Rgds,
Joshua from PG, Malaysia

"ch*********@postmaster.co.uk" wrote:

joshua siew wrote:
heeeeeeeeeeeeeeeeeelpp !!!

Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ???? I'm on
a project of programming a PLC devices. I need to send the ENQ ascii value
together with others data in a string into the plc. I'm also new in VC++ as
well as plc...

Thanks for the advice in advanced.

Rgds,
Joshua Siew


mystring[somewhere] = 5;

or perhaps clearer:

#define ENQ 0x5
....
mystring[somewhere] = ENQ;

Chris

May 26 '06 #3
or what about using ASCIIEncoding in VC++...any sample...?!????!?

"ch*********@postmaster.co.uk" wrote:

joshua siew wrote:
heeeeeeeeeeeeeeeeeelpp !!!

Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ???? I'm on
a project of programming a PLC devices. I need to send the ENQ ascii value
together with others data in a string into the plc. I'm also new in VC++ as
well as plc...

Thanks for the advice in advanced.

Rgds,
Joshua Siew


mystring[somewhere] = 5;

or perhaps clearer:

#define ENQ 0x5
....
mystring[somewhere] = ENQ;

Chris

May 26 '06 #4
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
chris,
thanks for the reply but according to BASIC sample program it looks like
this....
...
...
ENQ$ = CHR$(5)
...
...
OPEN "COM1":"AS#1"
SENDATA$="00FFTT204ABCD34"
PRINT #1, ENQ$;SENDATA$
...
...

I just want to translate this to MS VC++. Any idea ?
#include <stdio.h>
int main(int argc, char** argv)
{
FILE* serial = fopen("COM1:", "wb");
char alldata[] = { 5 /* ENQ */, '0', '0', 'F', 'F', 'T', 'T', '2', '0', '4',
'A', 'B', 'C', 'D', '3', '4' };
fwrite(alldata, 1, sizeof alldata, serial);
....
....
fclose(serial);
}
Rgds,
Joshua from PG, Malaysia

"ch*********@postmaster.co.uk" wrote:

joshua siew wrote:
> heeeeeeeeeeeeeeeeeelpp !!!
>
> Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ????
> I'm on
> a project of programming a PLC devices. I need to send the ENQ ascii
> value
> together with others data in a string into the plc. I'm also new in
> VC++ as
> well as plc...
>
> Thanks for the advice in advanced.
>
> Rgds,
> Joshua Siew


mystring[somewhere] = 5;

or perhaps clearer:

#define ENQ 0x5
....
mystring[somewhere] = ENQ;

Chris

May 30 '06 #5
Thanks a lot Ben.
Btw,
Any idea how to convert a given ASCII(1digits) code to HEX(2digit)...e.g
'A'=41H, 'B'=42H........If there's a function then it will surely be more
better....thanks in advanced.

-Joshua Siew

"Ben Voigt" wrote:
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
chris,
thanks for the reply but according to BASIC sample program it looks like
this....
...
...
ENQ$ = CHR$(5)
...
...
OPEN "COM1":"AS#1"
SENDATA$="00FFTT204ABCD34"
PRINT #1, ENQ$;SENDATA$
...
...

I just want to translate this to MS VC++. Any idea ?


#include <stdio.h>
int main(int argc, char** argv)
{
FILE* serial = fopen("COM1:", "wb");
char alldata[] = { 5 /* ENQ */, '0', '0', 'F', 'F', 'T', 'T', '2', '0', '4',
'A', 'B', 'C', 'D', '3', '4' };
fwrite(alldata, 1, sizeof alldata, serial);
....
....
fclose(serial);
}

Rgds,
Joshua from PG, Malaysia

"ch*********@postmaster.co.uk" wrote:

joshua siew wrote:
> heeeeeeeeeeeeeeeeeelpp !!!
>
> Can anyone tell me how the heck does VC++ create the ASCII 'ENQ' ????
> I'm on
> a project of programming a PLC devices. I need to send the ENQ ascii
> value
> together with others data in a string into the plc. I'm also new in
> VC++ as
> well as plc...
>
> Thanks for the advice in advanced.
>
> Rgds,
> Joshua Siew

mystring[somewhere] = 5;

or perhaps clearer:

#define ENQ 0x5
....
mystring[somewhere] = ENQ;

Chris


May 31 '06 #6
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Thanks a lot Ben.
Btw,
Any idea how to convert a given ASCII(1digits) code to HEX(2digit)...e.g
'A'=41H, 'B'=42H........If there's a function then it will surely be more
better....thanks in advanced.
For numeric literals, you already seem to have it mostly right:

'A', 0x41, and 65 are all equivalent.... mostly.
'A', char(0x41) and char(65) are exactly equivalent.
int('A'), 0x41 and 65 are exactly equivalent.
Most compilers do not flag a warning for a narrowing conversion of a
compile-time constant which fits in the smaller variable. Most calling
conventions also pass character arguments and integer arguments the same
way, one machine word on the stack or one CPU register. So the only time
the distinction really matters is when calling overloaded functions.

They are all stored identically inside the program, the compiler just
recognizes multiple forms for your convenience.

If you're asking for display purposes:
char a = 'a';
printf("%c", a); // a
printf("%d", a); // 97
printf("%x", a); // 61
printf("%xh", a); // 61h
printf("0x%02x", a); // 0x61

Pick your poison.

With the C++ standard library (using namespace std;):
cout << a; // a
cout << int(a); // 97
cout << hex << int(a); // 61
cout << hex << int(a) << "h"; // 61h
cout << "0x" << setw(2) << hex << int(a); // 0x61

-Joshua Siew

"Ben Voigt" wrote:
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
> chris,
> thanks for the reply but according to BASIC sample program it looks
> like
> this....
> ...
> ...
> ENQ$ = CHR$(5)
> ...
> ...
> OPEN "COM1":"AS#1"
> SENDATA$="00FFTT204ABCD34"
> PRINT #1, ENQ$;SENDATA$
> ...
> ...
>
> I just want to translate this to MS VC++. Any idea ?


#include <stdio.h>
int main(int argc, char** argv)
{
FILE* serial = fopen("COM1:", "wb");
char alldata[] = { 5 /* ENQ */, '0', '0', 'F', 'F', 'T', 'T', '2', '0',
'4',
'A', 'B', 'C', 'D', '3', '4' };
fwrite(alldata, 1, sizeof alldata, serial);
....
....
fclose(serial);
}
>
> Rgds,
> Joshua from PG, Malaysia
>
>
>
> "ch*********@postmaster.co.uk" wrote:
>
>>
>> joshua siew wrote:
>> > heeeeeeeeeeeeeeeeeelpp !!!
>> >
>> > Can anyone tell me how the heck does VC++ create the ASCII 'ENQ'
>> > ????
>> > I'm on
>> > a project of programming a PLC devices. I need to send the ENQ ascii
>> > value
>> > together with others data in a string into the plc. I'm also new in
>> > VC++ as
>> > well as plc...
>> >
>> > Thanks for the advice in advanced.
>> >
>> > Rgds,
>> > Joshua Siew
>>
>> mystring[somewhere] = 5;
>>
>> or perhaps clearer:
>>
>> #define ENQ 0x5
>> ....
>> mystring[somewhere] = ENQ;
>>
>> Chris
>>
>>


Jun 5 '06 #7
thanks

"Ben Voigt" wrote:
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Thanks a lot Ben.
Btw,
Any idea how to convert a given ASCII(1digits) code to HEX(2digit)...e.g
'A'=41H, 'B'=42H........If there's a function then it will surely be more
better....thanks in advanced.


For numeric literals, you already seem to have it mostly right:

'A', 0x41, and 65 are all equivalent.... mostly.
'A', char(0x41) and char(65) are exactly equivalent.
int('A'), 0x41 and 65 are exactly equivalent.
Most compilers do not flag a warning for a narrowing conversion of a
compile-time constant which fits in the smaller variable. Most calling
conventions also pass character arguments and integer arguments the same
way, one machine word on the stack or one CPU register. So the only time
the distinction really matters is when calling overloaded functions.

They are all stored identically inside the program, the compiler just
recognizes multiple forms for your convenience.

If you're asking for display purposes:
char a = 'a';
printf("%c", a); // a
printf("%d", a); // 97
printf("%x", a); // 61
printf("%xh", a); // 61h
printf("0x%02x", a); // 0x61

Pick your poison.

With the C++ standard library (using namespace std;):
cout << a; // a
cout << int(a); // 97
cout << hex << int(a); // 61
cout << hex << int(a) << "h"; // 61h
cout << "0x" << setw(2) << hex << int(a); // 0x61

-Joshua Siew

"Ben Voigt" wrote:
"joshua siew" <jo********@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
> chris,
> thanks for the reply but according to BASIC sample program it looks
> like
> this....
> ...
> ...
> ENQ$ = CHR$(5)
> ...
> ...
> OPEN "COM1":"AS#1"
> SENDATA$="00FFTT204ABCD34"
> PRINT #1, ENQ$;SENDATA$
> ...
> ...
>
> I just want to translate this to MS VC++. Any idea ?

#include <stdio.h>
int main(int argc, char** argv)
{
FILE* serial = fopen("COM1:", "wb");
char alldata[] = { 5 /* ENQ */, '0', '0', 'F', 'F', 'T', 'T', '2', '0',
'4',
'A', 'B', 'C', 'D', '3', '4' };
fwrite(alldata, 1, sizeof alldata, serial);
....
....
fclose(serial);
}
>
> Rgds,
> Joshua from PG, Malaysia
>
>
>
> "ch*********@postmaster.co.uk" wrote:
>
>>
>> joshua siew wrote:
>> > heeeeeeeeeeeeeeeeeelpp !!!
>> >
>> > Can anyone tell me how the heck does VC++ create the ASCII 'ENQ'
>> > ????
>> > I'm on
>> > a project of programming a PLC devices. I need to send the ENQ ascii
>> > value
>> > together with others data in a string into the plc. I'm also new in
>> > VC++ as
>> > well as plc...
>> >
>> > Thanks for the advice in advanced.
>> >
>> > Rgds,
>> > Joshua Siew
>>
>> mystring[somewhere] = 5;
>>
>> or perhaps clearer:
>>
>> #define ENQ 0x5
>> ....
>> mystring[somewhere] = ENQ;
>>
>> Chris
>>
>>


Jun 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Spamtrap | last post: by
22 posts views Thread by Martin Trautmann | last post: by
15 posts views Thread by Peter Afonin | last post: by
4 posts views Thread by Gregory Edigaroff | last post: by
5 posts views Thread by Jamie Risk | last post: by
4 posts views Thread by vcnewbie | last post: by
9 posts views Thread by =?Utf-8?B?UGhhbmlkaGFy?= | last post: by
12 posts views Thread by fermineutron | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.