By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

HOWTO: convert string to 8-bit bytes and back

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
> 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 discussion thread is closed

Replies have been disabled for this discussion.