PC Review


Reply
Thread Tools Rate Thread

Convert Ascii Character to decimal

 
 
=?Utf-8?B?RGlyZWN0b3IgLSBNaW52ZW50?=
Guest
Posts: n/a
 
      4th Mar 2005
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!
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      4th Mar 2005
Director - Minvent <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Mar 2005
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



 
Reply With Quote
 
Nick Malik [Microsoft]
Guest
Posts: n/a
 
      5th Mar 2005
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" <(E-Mail Removed)> wrote in
message news:3721E27B-147B-4389-BC1E-(E-Mail Removed)...
> 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!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Ascii string to decimal friend Microsoft VB .NET 8 30th Apr 2009 12:34 PM
Concatenate number w/decimal with ascii character ShoeHo65@yahoo.com Microsoft Access Queries 2 22nd Jul 2008 05:32 PM
How can i convert an ASCII character to decimal/hex in Excel? =?Utf-8?B?U3VyZWtoYQ==?= Microsoft Excel Worksheet Functions 1 8th Jun 2006 08:01 PM
How to convert an ascii code into a character? keithb Microsoft ASP .NET 1 15th Mar 2006 05:52 PM
How to: Convert character to ASCII code efernandes67 Microsoft Excel Misc 1 21st Jan 2006 04:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:37 AM.