byte to char

hi, i am receiving something from a stream, since this is a 'custom' stream, i dont have things like 'read integer' or read byte or things like that. to read an integer, which i read as binary, i have to read is character by character and then 'convert' it to numeric values or vice versa via modulus and exponentials (so far). byte value is a numeric value than can hold between 0 and 255 no? how do i get the ascii from that byte value (if function not in .net framework, using vb 6)?, also, if i receive a character, how do i retrieve is numeric byte value?
tnx
[574 byte] By [VooDooChicken] at [2007-12-28]
# 1

If you know the characters are ASCII then the following should work.

Public Function AsciiByteToChar(ByVal b As Byte) As Char

Dim barr() As Byte = New Byte() {b}

Dim carr() As Char = Encoding.ASCII.GetChars(barr)

Return carr(0)

End Function

JaredParsonsMSFT at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
tnx but not yet, as i said i am using vb6, so there is no such thing as encoding.ascii or any other space names, there is no .net framework at all. there were functions for that since basica or gwbasic, i just dont remember. i was able to do the part to convert number to text (with ChrW), now i need the part to convert a byte to its numeric value, without comparing value by value (like if something=ChrW(some counter in a loop), which would mean compare about 125 values in average just to convert one byte). i mean, if i have 'A' i need to get a 65 and so on
VooDooChicken at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3


in vb6..

Asc("A")

will return 65.. is this what you need?

jayson.ws.ds2.ci.ftsp at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

jayson.ws.ds2.ci.ftsp wrote:


in vb6..

Asc("A")

will return 65.. is this what you need?

I'm a tad confused, but isn't he looking to convert the byte to the character in which case didn't VB have a Chr() and Chr$() function to do that ... eg Chr(65) = "A".

The obvious thing here is that the byte value must contain the ASCII value for the character .... perhaps your value is encoded to something else?

DickDonny at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
I'm not sure if this is possible in VB6, but I have vb.net application which reads a file byte for byte.

In order to interpret special characters (such as norwegian special letters), I use the Chr() function to convert a byte to a char.

Example code:
'Create a file stream
Dim fi As New FileInfo("input.txt")
Dim fs As FileStream = fi.OpenRead()

Dim bytChar As Byte
Dim strChar as String
bytChar = fs.ReadByte
strChar = Chr(bytChar)

Cobolman at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

Hi,

See too please my reply at >>

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1230121&SiteID=1&mode=1

where i have written functions to go from;

  • Byte to Ascii

  • Ascii to Byte

  • Ascii to String

  • String to Ascii

  • Byte to String

  • String to Byte

Hope you find some of them useful?

Regards,

S_DS