bitwise
El método bitwise es un método objeto nos permite hacer desplazamiento de Bit en el código de error tantos Bits como queramos, siendo el número de Bits positivo hacia la izquierda, creando los Bits requeridos; y siendo el número de Bits negativo hacia la derecha, eliminando consigo ese número de Bits por ese lado.
- typepy
- characters585
- lines25
#!/usr/bin/env python # -*- coding: utf-8 -*- from Assets.ErrorsManager import ErrorsManager errors_manager:ErrorsManager = ErrorsManager() options:tuple[int] = (-10, -5, -3, -1, 0, 1, 3, 5, 10) value:int|str|list[int] for i, value in enumerate((105, "pB", [41, 1])): bits:int for bits in options: new_value:int|str|list[int] = errors_manager.bitwise(value, bits) print(( value, errors_manager.to_array_binary(value), bits, new_value, errors_manager.to_array_binary(new_value) ))
- typejs
- characters538
- lines22
"use strict"; /** @type {ErrorsManager} */ const errors_manager = new ErrorsManager(), /** @type {Array.<number>} */ options = [-10, -5, -3, -1, 0, 1, 3, 5, 10]; [105, "pB", [41, 1]].forEach((value, i) => options.forEach(bits => { /** @type {number|String|Array.<number>} */ const new_value = errors_manager.bitwise(value, bits); console.log([ value, errors_manager.to_array_binary(value), bits, new_value, errors_manager.to_array_binary(new_value) ]); }));
El resultado de estas pruebas son los siguientes:
Valor | Binario | Bits | Desplazado | Binario desplazado |
---|---|---|---|---|
105 | ["101001", "000001"] | -10 | 0 | ["000000"] |
105 | ["101001", "000001"] | -5 | 3 | ["000011"] |
105 | ["101001", "000001"] | -3 | 13 | ["001101"] |
105 | ["101001", "000001"] | -1 | 52 | ["110100"] |
105 | ["101001", "000001"] | 0 | 105 | ["101001", "000001"] |
105 | ["101001", "000001"] | 1 | 210 | ["010010", "000011"] |
105 | ["101001", "000001"] | 3 | 840 | ["001000", "001101"] |
105 | ["101001", "000001"] | 5 | 3360 | ["100000", "110100"] |
105 | ["101001", "000001"] | 10 | 107520 | ["000000", "010000", "011010"] |
pB | ["101001", "000001"] | -10 | A | ["000000"] |
pB | ["101001", "000001"] | -5 | DA | ["000011", "000000"] |
pB | ["101001", "000001"] | -3 | NA | ["001101", "000000"] |
pB | ["101001", "000001"] | -1 | 0A | ["110100", "000000"] |
pB | ["101001", "000001"] | 0 | pB | ["101001", "000001"] |
pB | ["101001", "000001"] | 1 | SD | ["010010", "000011"] |
pB | ["101001", "000001"] | 3 | IN | ["001000", "001101"] |
pB | ["101001", "000001"] | 5 | g0 | ["100000", "110100"] |
pB | ["101001", "000001"] | 10 | AQa | ["000000", "010000", "011010"] |
[41, 1] | ["101001", "000001"] | -10 | [0] | ["000000"] |
[41, 1] | ["101001", "000001"] | -5 | [3, 0] | ["000011", "000000"] |
[41, 1] | ["101001", "000001"] | -3 | [13, 0] | ["001101", "000000"] |
[41, 1] | ["101001", "000001"] | -1 | [52, 0] | ["110100", "000000"] |
[41, 1] | ["101001", "000001"] | 0 | [41, 1] | ["101001", "000001"] |
[41, 1] | ["101001", "000001"] | 1 | [18, 3] | ["010010", "000011"] |
[41, 1] | ["101001", "000001"] | 3 | [8, 13] | ["001000", "001101"] |
[41, 1] | ["101001", "000001"] | 5 | [32, 52] | ["100000", "110100"] |
[41, 1] | ["101001", "000001"] | 10 | [0, 16, 26] | ["000000", "010000", "011010"] |
Valor | Binario | Bits | Desplazado | Binario desplazado |