473,322 Members | 1,501 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,322 software developers and data experts.

How to change a String into a Byte to show a ASCII Character

Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).

Can anybody help me to change this string into a byte ?
Thank you,

Tobias

Mar 13 '07 #1
5 1448
On Mar 13, 11:12 am, "Tobi" <tobid...@googlemail.comwrote:
Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).

Can anybody help me to change this string into a byte ?
Thank you,

Tobias

Try
Convert.ToByte("0010101")

Mar 13 '07 #2
On 13 Mrz., 17:27, "Jeremy Kitchen" <J.t.Kitc...@gmail.comwrote:
On Mar 13, 11:12 am, "Tobi" <tobid...@googlemail.comwrote:
Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).
Can anybody help me to change this string into a byte ?
Thank you,
Tobias

Try
Convert.ToByte("0010101")
Its not working, i get an overflow (Make sure your not dividing
through zero...)
any other ideas ?

Mar 13 '07 #3
On Mar 13, 11:42 am, "Tobi" <tobid...@googlemail.comwrote:
On 13 Mrz., 17:27, "Jeremy Kitchen" <J.t.Kitc...@gmail.comwrote:
On Mar 13, 11:12 am, "Tobi" <tobid...@googlemail.comwrote:
Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).
Can anybody help me to change this string into a byte ?
Thank you,
Tobias
Try
Convert.ToByte("0010101")

Its not working, i get an overflow (Make sure your not dividing
through zero...)
any other ideas ?
Oops That creates trouble because it isn't treating it as a byte
array.

Try this function instead. You will want to add length checking etc.

Function GetChar(ByVal MybyteArray As String) As Char
Dim i As Integer = MybyteArray.Length - 1
Dim MyByte As Byte = 0
While i >= 0
If MybyteArray.Chars(i) = "1"c Then
MyByte = MyByte + 2 ^ i
End If
i -= 1
End While
Return Convert.ToChar(MyByte)
End Function

Mar 13 '07 #4
Convert.ToByte("0010101", 2)

"Jeremy Kitchen" <J.*********@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
On Mar 13, 11:42 am, "Tobi" <tobid...@googlemail.comwrote:
>On 13 Mrz., 17:27, "Jeremy Kitchen" <J.t.Kitc...@gmail.comwrote:
On Mar 13, 11:12 am, "Tobi" <tobid...@googlemail.comwrote:
Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should
be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).
Can anybody help me to change this string into a byte ?
Thank you,
Tobias
Try
Convert.ToByte("0010101")

Its not working, i get an overflow (Make sure your not dividing
through zero...)
any other ideas ?

Oops That creates trouble because it isn't treating it as a byte
array.

Try this function instead. You will want to add length checking etc.

Function GetChar(ByVal MybyteArray As String) As Char
Dim i As Integer = MybyteArray.Length - 1
Dim MyByte As Byte = 0
While i >= 0
If MybyteArray.Chars(i) = "1"c Then
MyByte = MyByte + 2 ^ i
End If
i -= 1
End While
Return Convert.ToChar(MyByte)
End Function

Mar 13 '07 #5
On 13 Mrz., 20:37, "Mudhead" <nowh...@here.comwrote:
Convert.ToByte("0010101", 2)

"Jeremy Kitchen" <J.t.Kitc...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
On Mar 13, 11:42 am, "Tobi" <tobid...@googlemail.comwrote:
On 13 Mrz., 17:27, "Jeremy Kitchen" <J.t.Kitc...@gmail.comwrote:
On Mar 13, 11:12 am, "Tobi" <tobid...@googlemail.comwrote:
Hi,
i have a problem.
I want to get Ascii Caracters out of a 7 Bit long Byte, that should
be
no problem with the getString Method, but i dont have a byte i have a
String which contains only an array of bits (i.e. 0010101).
Can anybody help me to change this string into a byte ?
Thank you,
Tobias
Try
Convert.ToByte("0010101")
Its not working, i get an overflow (Make sure your not dividing
through zero...)
any other ideas ?
Oops That creates trouble because it isn't treating it as a byte
array.
Try this function instead. You will want to add length checking etc.
Function GetChar(ByVal MybyteArray As String) As Char
Dim i As Integer = MybyteArray.Length - 1
Dim MyByte As Byte = 0
While i >= 0
If MybyteArray.Chars(i) = "1"c Then
MyByte = MyByte + 2 ^ i
End If
i -= 1
End While
Return Convert.ToChar(MyByte)
End Function
Sorry this link is not working

Mar 13 '07 #6

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

Similar topics

8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
12
by: John Leslie | last post by:
I need to write a string to a file in EBCDIC. Do I need to do it character by character using a translation table, or is there a function to translate the whole string? (I am aware that I can...
9
by: Andrea | last post by:
how can I convert a byte to a string ? Any idea? Andrea
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
6
by: KA Kueh | last post by:
Dear all, I have a requirement to replace the ' character with ASCII character (146) in C# but it seems that when I do the following the conversion is lost. char t = Convert.ToChar(146);...
4
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi Does anyone know how to stay connected to the server and at the same time i can pass the string to and from the module to the form..... What I want: I put the connection at the...
2
by: Alpha | last post by:
Hi, I'm able to make connection to a server using socket connection. However, when I send a command string the server just ignores it. All command string needs to start with "0xF9" at Byte 0. ...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.