#### Share via

160 Reputation points
2024-01-09T20:50:57.8733333+00:00

Hello gurus

I'm using Win32_NetworkAdapter and am having trouble showing uint64 Speed to the user in my app.

Need to convert the long bits per second to MegaBit or Gigabit according to the Speed value.

Running the code on my system, I've got these numbers:

9223372036854775807 for Intel Lan

144400000 for Qualcomm WiFi

1000000000 for Private Network

How's the formula and is there some built-in .NET function to east the conversion?

For size, I'd use this, but for bits per second, no idea how to match it to cover all possible values, any help is highly appreciated:

``````Select Case MySize
Case 0 To 1023
Return MySize.ToString + " Bytes"
Case 1024 To 1048575
Return (MySize \ 1024).ToString + " KB"
Case 1048576 To 1073741823
Return (MySize \ 1048576).ToString + " MB"
Case 1073741824 To 1099511627775
Return String.Format("{0:0.00}", MySize / 1073741824) + " GB"
End Select
``````
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,704 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,689 questions

1. 30,046 Reputation points Microsoft Vendor
2024-01-10T01:50:46.3966667+00:00

Hi @Sani Love ,

For the speed in bits per second, you can use the following code to convert it to Kbps, Mbps, or Gbps based on the value.

``````    Function ConvertSpeedToReadable(speedInBitsPerSecond As ULong) As String
Dim speed As Double = Convert.ToDouble(speedInBitsPerSecond)

If speed < 1000000 Then
Return \$"{speed / 1000:F2} Kbps"
ElseIf speed < 1000000000 Then
Return \$"{speed / 1000000:F2} Mbps"
Else
Return \$"{speed / 1000000000:F2} Gbps"
End If
End Function
``````

Best Regards.

Jiachen Li