473,385 Members | 1,769 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.

HOWTO: convert string to 8-bit bytes and back

None of the Converter tyeps (eg ASCIIEncoding )let you
convert between string and 8-bit bytes (0-255).

It took me a long time to find there is a way, well, at
least 2 ways.....here is the way to go fromn string to
bytes....

'Method 1
Dim Enc As Encoding = Encoding.GetEncoding(1252)
Dim pBytes() As Byte = Enc.GetBytes(S)

'Method 2
Dim pBytes() As Byte = Encoding.Default.GetBytes(S)
Dermot Balson
Free VBA code for user interfaces, internet connectivity,
encryption
http://www.webace.com.au/~balson/Ins...l/Default.html
Last updated August 2003
Nov 20 '05 #1
3 13600
"dermot" <de********************@hotmail.com> scripsit:
None of the Converter tyeps (eg ASCIIEncoding )let you
convert between string and 8-bit bytes (0-255).


ASCII is 7-Bit.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Hi Dermot,

Are you having a problem with conversion? Also, ASCII is 7-bits, 0-127.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"dermot" <de********************@hotmail.com> wrote in message
news:0c****************************@phx.gbl...
None of the Converter tyeps (eg ASCIIEncoding )let you
convert between string and 8-bit bytes (0-255).

It took me a long time to find there is a way, well, at
least 2 ways.....here is the way to go fromn string to
bytes....

'Method 1
Dim Enc As Encoding = Encoding.GetEncoding(1252)
Dim pBytes() As Byte = Enc.GetBytes(S)

'Method 2
Dim pBytes() As Byte = Encoding.Default.GetBytes(S)
Dermot Balson
Free VBA code for user interfaces, internet connectivity,
encryption
http://www.webace.com.au/~balson/Ins...l/Default.html
Last updated August 2003

Nov 20 '05 #3
> ASCII is 7-Bit

thanks Herfried, that was exactly my problem. I needed 8-
bit conversion which is how the Windows APIs work for VB6.

That's why I posted the sample code, to help others with
the same problem.

regards

Dermot
Nov 20 '05 #4

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

Similar topics

2
by: Krish | last post by:
Hi, How to convert "1283912839E-5" string (in scientific format) to a decimal. Convert.ToDecimal("1283912839E-5") is throwing "Input string is not in correct format" exception. Is the...
5
by: Brian Reed | last post by:
I have a class that I want to serialize to an XML string. I want the XML to serialize to utf-8 encoding. When I serialize to an XML file, the data looks great. When I try to serialize to a String...
4
by: CSharpener | last post by:
This should be *so* easy! How do I convert a Byte or int to a binary string representation in C# In JavaScript, it goes like this for an int: javascript:(123).toString(2 or...
2
by: Matthias S. | last post by:
Hi, I'm writing a logging utility and I need to wrap the string.Format method. I'd like to call the Trace method of MyLog like this: MyLog.Trace("Var1:{0};Var2:{1};", MyVar1, MyVar2); The...
2
by: ATS | last post by:
HOWTO Read from stdout without blocking. Please help, I have an app that is launching another process, where it is letting the new process inherit the STD-IN/OUT hanldes. The goal is to let...
3
by: ProJee | last post by:
1. How to pass chr(1) (or another special char below 32) to a method in a webservice? It raises an exception when I try to pass it through webservice.htc 2. How to pass chr(255) It doesn't...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
7
by: dmitrey | last post by:
howto make Python list from numpy.array? Thx, D.
6
by: fnoppie | last post by:
Hi, I am near to desperation as I have a million things to get a solution for my problem. I have to post a multipart message to a url that consists of a xml file and an binary file (pdf)....
3
by: Larry Hale | last post by:
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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: 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
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...

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.