473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1691

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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.