Assign positions to convert to a decimal

1

Good day to all, I hope and you can help me because I can not move forward.

I have a checklistbox that is filled with sp and activated by checkbox, the sp brings me the following values:

 Text                                  SwitchId     Switch
Búsqueda de direcciones                   0            1
Historial de ruta                         1            2
Funcionalidad de Geocercas                2            4
Generación de reportes                    3            8
Alertas                                   4           16
Disparo de inmovilización                 5           32
Comando de cambio de tasa de transmisión  6           64
Administracion de conductores             7           128
Soporte MDT                               8           256
Puntos de Interés                         9           512
Localización Web                          10          1024
Salida SMS                                11          2048
Configuración de recursos                 12          4096
Reportes Programados                      13          8192
Capacidades de Administrador              14          16384
Comandos de MDT                           15          32768
Fleet 360                                 16          65536
Móvil Habilitado                          17          131072
Cuenta visualizadora                      18          262144
Visualizador de Conductores               19          524288
Desactivar la actualización del 
  cuentakilómetros                        20          1048576
Contador de Horas                         21          2097152
SEGURIDAD EN MANEJO                       22          4194304
Gestión de Tareas                         23          8388608
Gestión de Jerarquías de Subcuentas       24          16777216
Asignación Dinámica de Subcuentas         25          33554432
Gestión de Grupos de Vehículos 
  de Subcuentas                           26          67108864
Gestión de Alarmas                        27          134217728
Gestión de riesgos                        28          268435456
Tablero                                   29          536870912
RSS Enabled                               30          1073741824
Tablero de control Pointer                31          2147483648

Each of the clients that we manage in the area, has assigned a number that is the following (example) Swich = 523263, this number converted to Binary would be the following (1111111101111111111) and corresponds to the switches that are activated to each of the clients, for each of them is dynamic and not all, have the same activated.

What I would like is that when the client is selected from a droplist, the switches will automatically activate to achieve the number that corresponds to the binary number. That is, each text has a value assigned to the switch and it gets a value that, when added together, gives me the total value of the activated permissions.

I hope to have explained myself concretely, does anyone know how I could achieve my goal?

Thank you.

    
asked by Ric_hc 26.10.2018 в 20:17
source

1 answer

0

Surely you can solve it by doing 2 raised to each position labeled, that is, it would be something like this:

double res = 0;
foreach (int pos in checkedListBox1.CheckedIndices)
    res += Math.Pow(2, pos);

I hope it serves you.

Good luck!

    
answered by 27.10.2018 в 01:01