473,417 Members | 1,477 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,417 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 32019
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....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.