Click here to Skip to main content
15,795,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am using the InTheHand GitHub package. One of the classes provided by that package is
the BluetoothInfo class. One of the properties provided by this class is the DeviceAddress property. This property is of class BluetoothAddress. It is possible to create a BluetoothDevice object from a BluetoothInfo, but the BluetoothAddress is represented as an equivalent uint.

I would like to know how to convert a DeviceAddress into an equivalent unit. The general algorithm for converting an IP Address to a uint doesn't seem to work


What I have tried:

I tried several different algorithms for converting an IP Address to an equivalent uint, but the program hangs without timeout when I try:

BluetoothDevice device = await BluetoothDevice.FromBluetoothAddressAsync(bluetoothAddress)
where bluetoothAddress is a uint produced by a method that converts an IP Address to an equivalent uint.
Updated 12-Nov-21 22:57pm

1 solution

Assuming an IP address of the form A:B:C:D, where each field can be in the range 0-255, it is a simple matter to convert it into a 32 bit unsigned integer:
uint[] ip = { 192,168,2,1};
uint num = ip[0] << 24;
num += ip[1] << 16;
num += ip[2] << 8;
num += ip[3];
Console.WriteLine($"num: {num}");
Share this answer
Stafford Martin 2021 13-Nov-21 11:46am    
This is one of the algorithms I tried. It did not work. That makes sense. It hardly makes sense to have a BluetoothAddress class if it is merely an IP Address. An attempt to access the device using an address created via this algorithm causes the program to hang. Using the BluetoothInfo from this the associated BluetoothDevice object is derived doesn't. I need the BluetoothDevice object because it gives me an event that I can use to know when the connection status of a device is changed. Using the BluetoothInfo I am forced to use a timer to keep checking the device status to discover if it has changed.
Richard MacCutchan 13-Nov-21 11:56am    
" need the BluetoothDevice object"
Sorry, I don't know what that is.
Stafford Martin 2021 13-Nov-21 12:22pm    
It is one of the classes in the InTheHand GitHub package. Of course, if you know of a completely different solution that doesn't use that package, I would be delighted.
Richard Deeming 15-Nov-21 4:32am    
You'll need to ask the authors of that project for help in using their library. Unless they've disabled it, there should be an "Issues" list where you can post your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900