472,984 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

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 1680

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
22
by: Martin Trautmann | last post by:
Hi all, is there any kind of 'hiconv' or other (unix-like) conversion tool that would convert UTF-8 to HTML (ISO-Latin-1 and Unicode)? The database output is UTF-8 or UTF-16 only - Thus almost...
15
by: Peter Afonin | last post by:
Hello, I'm struggling with the string conversion to MD5 which I've never user before. I have a string that I need to encode which looks approximately like this: ...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
4
by: Gregory Edigaroff | last post by:
Hello, Everybody! Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest, so I believe somebody have a solution for it. I need either a full...
5
by: Jamie Risk | last post by:
This is the code snippet that I've come up to convert a byte to string. Is there a best practiced method for such a conversion? - Jamie public static string ByteArrayToString(byte array) {...
4
by: vcnewbie | last post by:
Hi I'm maintaining a VisualC++ project to increase its security regarding stored passwords. I thought about using SHA256Managed to create a hash for the password when creating a user and when...
9
by: =?Utf-8?B?UGhhbmlkaGFy?= | last post by:
Hi, I'm developing a Winform application in C#( .net 2.0). I've a dialog box where user can input text and that text would be sent across to other machine using sockets. When the user enters...
12
by: fermineutron | last post by:
I am trying to write a function which will convert a large ascii number, say 100 ascii digits, to its binary representation. It seems that evey algorithm I am trying to think of is backwards. ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.