打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Byte Array to String

转为String的方法,System.Text.UTF8Encoding.Unicode.GetString(buffer)

 

 Byte Array TO Char:

To convert byte array to char value, we have static method of BitConverter class named ToChar (). This method takes byte array and starting index of the byte array from where conversion should start and returns a char value.

To demonstrate make a window application. Drag one button on form.

Now write the following code on Button click event:

C#

private void btn_convertchar_Click(object sender, EventArgs e)

        {

            char c = 'a';

            byte[] br = BitConverter.GetBytes(c);

            string str = BitConverter.ToString(br);

            MessageBox.Show("BYTE ARRAY IS " + str + "\nCHARACTER IS " + BitConverter.ToChar(br, 0));

        }

VB

Private Sub btn_convertchar_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim c As Char = "a"c

        Dim br As Byte() = BitConverter.GetBytes(c)

        Dim str As String = BitConverter.ToString(br)

        MessageBox.Show(("BYTE ARRAY IS " & str & vbLf & "CHARACTER IS ") + BitConverter.ToChar(br, 0))

    End Sub

This is simple code to convert byte array to char value.

Byte Array to Double:

To convert byte array to double value, we have static method of BitConverter class named ToDouble (). This method takes byte array and starting index of the byte array from where conversion should start and returns a double value.

To demonstrate make a window application. Drag one button on form.

Now write the following code on Button click event:

C#

private void btn_double_Click(object sender, EventArgs e)

        {

            double d = 1.11111111111111;

            byte[] br = BitConverter.GetBytes(d);

            string str = BitConverter.ToString(br);

            MessageBox.Show("BYTE ARRAY IS " + str + "\nDouble value IS " + BitConverter.ToDouble(br, 0));

        }

VB

Private Sub btn_double_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim d As Double = 1.11111111111111

        Dim br As Byte() = BitConverter.GetBytes(d)

        Dim str As String = BitConverter.ToString(br)

        MessageBox.Show(("BYTE ARRAY IS " & str & vbLf & "Double value IS ") + BitConverter.ToDouble(br, 0))

    End Sub

This is simple code to convert byte array to double value.

Byte Array to Single:

To convert byte array to single value, we have static method of BitConverter class named ToSingle (). This method takes byte array and starting index of the byte array from where conversion should start and returns a single value.

To demonstrate make a window application. Drag one button on form.

Now write the following code on Button click event:

C#

private void btn_single_Click(object sender, EventArgs e)

        {

            Single s = 2.5f;

            byte[] br = BitConverter.GetBytes(s);

            string str = BitConverter.ToString(br);

            MessageBox.Show("BYTE ARRAY IS " + str + "\nSingle value IS " + BitConverter.ToSingle(br, 0));

        }

VB

Private Sub btn_single_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim s As [Single] = 2.5F

        Dim br As Byte() = BitConverter.GetBytes(s)

        Dim str As String = BitConverter.ToString(br)

        MessageBox.Show(("BYTE ARRAY IS " & str & vbLf & "Single value IS ") + BitConverter.ToSingle(br, 0))

    End Sub

This is simple code to convert byte array to single value.

Byte Array to Integer:

To convert byte array to Integer value, we have static method of BitConverter class named ToInt32 (). This method takes byte array and starting index of the byte array from where conversion should start and returns an integer value.

To demonstrate make a window application. Drag one button on form.

Now write the following code on Button click event:

C#

private void btn_int_Click(object sender, EventArgs e)

        {

            int d = 100;

            byte[] br = BitConverter.GetBytes(d);

            string str = BitConverter.ToString(br);

            MessageBox.Show("BYTE ARRAY IS " + str + "\nInteger value IS " + BitConverter.ToInt32(br, 0));

        }

VB

Private Sub btn_int_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim d As Integer = 100

        Dim br As Byte() = BitConverter.GetBytes(d)

        Dim str As String = BitConverter.ToString(br)

        MessageBox.Show(("BYTE ARRAY IS " & str & vbLf & "Integer value IS ") + BitConverter.ToInt32(br, 0))

    End Sub

This is simple code to convert byte array to integer value.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP BIT CONVERTER APPLICATION";

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP BIT CONVERTER APPLICATION"

    End Sub

This simple article

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
笔记7:vb.net的异步读写数据流(使用线程、委托)
自制UG标准零件系库[源代码]
VB.NET语法规则三大要素
C# Byte[]数组读取和写入文件
Byte数组与String类型的转换
selectresult.jsp
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服