472,363 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Convert Ascii Character to decimal

Hi,

I am reading from a serial port from a device which sends over an ascii
character. It uses the full extended 256 character set and therefore has
non-printing characters too. So what i want to do is convert the input to the
associated decimal.

I.E
ASCII Char 'NUL' will become 0
ASCII Char 'SOH' will become 1
ASCII Char 'STX' will become 2
ASCII Char '0' will become 48
ASCII Char '1' will become 49

All the way to up to the decimal value 255

I know it must be some thing simple but I can't find it! I'm using C#.net or
VB.net
Thanks in advance
--
If at first you don't succeed... Hide the evidence that you tried!
Nov 22 '05 #1
3 31851
Director - Minvent <Di*************@discussions.microsoft.com> wrote:
I am reading from a serial port from a device which sends over an ascii
character. It uses the full extended 256 character set and therefore has
non-printing characters too.
ASCII doesn't have 256 characters.
So what i want to do is convert the input to the
associated decimal.

I.E
ASCII Char 'NUL' will become 0
ASCII Char 'SOH' will become 1
ASCII Char 'STX' will become 2
ASCII Char '0' will become 48
ASCII Char '1' will become 49

All the way to up to the decimal value 255

I know it must be some thing simple but I can't find it! I'm using C#.net or
VB.net


If you want to go up to 256, you need to know what character encoding
it's using for 128-256. For 0-127, you can just cast the character to
an int.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Hi,

You can use the Convert.ToChar(integer) for this in C# and VBNet while in
VBNet there is the maybe even stronger instruction Chrw(integer), this of
course all depended from the by you used codetable.

http://msdn.microsoft.com/library/de...ochartopic.asp

http://msdn.microsoft.com/library/de...l/vafctchr.asp

I hope this helps?

Cor

Nov 22 '05 #3
Is it sending over a character or a byte? If it is a byte, then you don't
have to convert to a number... it already is a number. If it is sending a
character, then somewhere along the way, the binary value was mapped to a
code table to get a character. You'd need to map it back!

What mechanism are you using to read the byte? a COM component perhaps?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Director - Minvent" <Di*************@discussions.microsoft.com> wrote in
message news:37**********************************@microsof t.com...
Hi,

I am reading from a serial port from a device which sends over an ascii
character. It uses the full extended 256 character set and therefore has
non-printing characters too. So what i want to do is convert the input to
the
associated decimal.

I.E
ASCII Char 'NUL' will become 0
ASCII Char 'SOH' will become 1
ASCII Char 'STX' will become 2
ASCII Char '0' will become 48
ASCII Char '1' will become 49

All the way to up to the decimal value 255

I know it must be some thing simple but I can't find it! I'm using C#.net
or
VB.net
Thanks in advance
--
If at first you don't succeed... Hide the evidence that you tried!

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Director - Minvent | last post by:
Hi, I am reading from a serial port from a device which sends over an ascii character. It uses the full extended 256 character set and therefore has non-printing characters too. So what i want...
3
by: Java and Swing | last post by:
I have some output stored in a string that looks like.. >> x '\x01\xee\x1eo\xc3+\x8b\x83\xfad\xf6E\xaa\x0ea/I\x96\x83\xf5G\xa3\rQ\xfcH\xee\r' According to,...
7
by: Philipp H. Mohr | last post by:
Hello, I am trying to xor the byte representation of every char in a string with its predecessor. But I don't know how to convert a char into its byte representation. This is to calculate the...
30
by: John Carroll | last post by:
Does anyone have a function or procedure for converting integers to character strings? Thank you, John
11
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected...
4
by: Trond Hoiberg | last post by:
I was wondering if someone in here knows if it is possible to convert a letter (a, b, c....) to the ISO Latin-1 Character Set Decimal code? a= a b=b c=c I know it is possible but i was looking...
16
by: akarui.tomodachi | last post by:
What is the most easiest way to convert an integer value to ASCII character format ? I tried with sprintf(). It works. Is there any other way to do that ? Objective:: I like to convert an...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.