elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 09:01  


Tema destacado: Deseas probar algunas mejoras a la interfaz del foro? Prueba cake! acerca de

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  [RETO] Reemplazo de Operadores Binarios.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [RETO] Reemplazo de Operadores Binarios.  (Leído 610 veces)
79137913


Desconectado Desconectado

Mensajes: 780


4 Esquinas


Ver Perfil WWW
[RETO] Reemplazo de Operadores Binarios.
« en: 7 Abril 2011, 17:19 »

HOLA!!!

Me parece que va a estar bueno, el reto consiste en crear 3 funciones:
(Usa Long por la rapidez y para soportar numeros grandes)

Código:
AndAlt(Byte1 As Long, Byte2 As Long) as Long
OrAlt(Byte1 As Long, Byte2 As Long) as Long
XorAlt(Byte1 As Long, Byte2 As Long) as Long

Creo que mucho no hay que explicar las funciones deben devolver lo mismo que los operadores binarios convencionales.

P.D: Me habia olvidado... NotAlt(Byte1 As Long)
P.D2: Creo que es obvio, no se pueden usar los operadores en las funciones.
P.D3:Para los que no saben como funcionan los operadores binarios:
Código:
Primero los valores se convierten a binario y luego se hace esto:

And: Solo si se comparte el mismo bit en ambos numeros.
Valor 1 = 0 0 1 0 1 0 0 0
Valor 2 = 1 0 1 1 1 0 1 1
        -----------------
Result  = 0 0 1 0 1 0 0 0

Or : Solo si uno tiene un bit "1".
Valor 1 = 0 0 1 0 1 0 0 0
Valor 2 = 1 0 1 1 1 0 1 1
        -----------------
Result  = 1 0 1 1 1 0 1 1

Xor : Solo si uno tiene un bit "1" y el otro "0".
Valor 1 = 0 0 1 0 1 0 0 0
Valor 2 = 1 0 1 1 1 0 1 1
        -----------------
Result  = 1 0 0 1 0 0 1 1

GRACIAS POR LEER!!!


« Última modificación: 8 Abril 2011, 17:46 por 79137913 » En línea

"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

 79137913                          *Shadow Scouts Team*                                                          Resumenes Cs.Economicas
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: [RETO] Reemplazo de Operadores Binarios.
« Respuesta #1 en: 7 Abril 2011, 19:56 »

.
interesante, regresando le hechare mano de obra.

Dulces Lunas!¡.


En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: [RETO] Reemplazo de Operadores Binarios.
« Respuesta #2 en: 7 Abril 2011, 21:36 »

.
Aun tiene unos HORRORES al tratar con numeros negativos. xP.

La funcion Not es mas facil que nada al tratarse de numeros decimales xP.

Al rato las mejoro un poco ahora me tengo que ir llevo 2 horas de retraso. xS.

Código
 
Option Explicit
 
Public Enum tBase
   [  Base2  ] = 2
   [  Base8  ] = 8
   [  Base10  ] = 10  '   //  Se obvia como entrada    (La dejo solo para verificar cogruencia)
   [  Base16  ] = 16
End Enum
 
Const conlnLong         As Long = &H20  '   //  Bites de un Long.

Public Function Dec2Bin(ByVal CurVal As Long) As String
Dim lng_lim                         As Long
Dim lng_index                       As Long
Dim byt_res                         As Byte
Dim boo_min                         As Boolean
   If (CurVal < 0) Then
       boo_min = True
       CurVal = CurVal * -1 - 1
       Dec2Bin = String$(conlnLong, "1")
   Else
       Dec2Bin = String$(conlnLong, "0")
   End If
   For lng_index = 0 To conlnLong - 1
       byt_res = CurVal Mod 2
       If (boo_min = True) Then
           If (byt_res = 1) Then
               byt_res = 0
           Else
               byt_res = 1
           End If
           Mid$(Dec2Bin, conlnLong - lng_index, 1) = byt_res
       Else
           Mid$(Dec2Bin, conlnLong - lng_index, 1) = byt_res
       End If
       CurVal = CurVal \ 2
       If (CurVal = 0) Then Exit For
   Next
End Function
 
'   //  Hex no afecta a bases inferiores por ello lo dejo.
Public Function Base2Dec(ByRef inval As String, ByRef InBase As tBase) As Long
Dim lng_lenStr&
Dim lng_Pointer&
Dim lng_Potencia&
Dim lng_limit&
 
   lng_lenStr& = Len(inval)
 
   If (lng_lenStr& >= conlnLong) Then
       lng_lenStr& = conlnLong
       lng_limit& = 2
   Else
       lng_limit& = InStr(1, inval, "-")
   End If
 
   lng_Potencia& = 0
 
   For lng_Pointer& = lng_lenStr& To lng_limit& Step -1
      Base2Dec = Base2Dec + CLng("&H" & Mid$(inval, lng_Pointer, 1)) * InBase ^ lng_Potencia&
       lng_Potencia& = lng_Potencia& + 1
   Next lng_Pointer&
 
   If (Mid$(inval, 1, 1) = "1") Then Base2Dec = Base2Dec * -1
 
End Function
 
Public Function AndAlt(Byte1 As Long, Byte2 As Long) As Long
Dim str1        As String
Dim str2        As String
Dim str3        As String * conlnLong
Dim i           As Byte
 
   str1 = Dec2Bin(Byte1)
   str2 = Dec2Bin(Byte2)
 
   For i = 1 To conlnLong
       If (Mid$(str1, i, 1) = "1") Then
           If (Mid$(str1, i, 1) = Mid$(str2, i, 1)) Then
               Mid$(str3, i, 1) = 1
           Else
               Mid$(str3, i, 1) = 0
           End If
       Else
           Mid$(str3, i, 1) = 0
       End If
   Next i
 
   AndAlt = Base2Dec(str3, [  Base2  ])
 
End Function
 
Public Function OrAlt(Byte1 As Long, Byte2 As Long) As Long
Dim str1        As String
Dim str2        As String
Dim str3        As String * conlnLong
Dim i           As Byte
 
   str1 = Dec2Bin(Byte1)
   str2 = Dec2Bin(Byte2)
 
   For i = 1 To conlnLong
       If (Mid$(str1, i, 1) = "1") Then
           Mid$(str3, i, 1) = 1
       ElseIf (Mid$(str2, i, 1) = "1") Then
           Mid$(str3, i, 1) = 1
       Else
           Mid$(str3, i, 1) = 0
       End If
   Next i
 
   OrAlt = Base2Dec(str3, [  Base2  ])
 
End Function
 
Public Function XorAlt(Byte1 As Long, Byte2 As Long) As Long
Dim str1        As String
Dim str2        As String
Dim str3        As String * conlnLong
Dim i           As Byte
 
   str1 = Dec2Bin(Byte1)
   str2 = Dec2Bin(Byte2)
 
   For i = 1 To conlnLong
       If (Mid$(str1, i, 1) = "1") Then
           If (Mid$(str2, i, 1) = "0") Then
               Mid$(str3, i, 1) = 1
           Else
               Mid$(str3, i, 1) = 0
           End If
       Else
           If (Mid$(str2, i, 1) = "1") Then
               Mid$(str3, i, 1) = 1
           Else
               Mid$(str3, i, 1) = 0
           End If
       End If
   Next i
 
   XorAlt = Base2Dec(str3, [  Base2  ])
 
End Function
 
Public Function NotAlt(Byte1 As Long) As Long
   NotAlt = (Byte1 + 1) * -1
End Function
 
 

Ejemplo Basico:

Código
 
Private Sub Form_Load()
   MsgBox XorAlt(AndAlt(NotAlt(7451), OrAlt(10, 456)), 1) & vbNewLine & _
          CStr((Not 7451) And (10 Or 456) Xor 1)
End Sub
 
 

claro esta que los operadores binarios son los mas rapidos y estos ni ninguno va asuperar la velocidad de los originales.

Temibles Lunas!¡.
« Última modificación: 8 Abril 2011, 07:47 por BlackZeroX▓▓▒▒░░ » En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
79137913


Desconectado Desconectado

Mensajes: 780


4 Esquinas


Ver Perfil WWW
Re: [RETO] Reemplazo de Operadores Binarios.
« Respuesta #3 en: 8 Abril 2011, 14:12 »

HOLA!!!

Aca les dejo mi solucion:

Las funciones son independientes...

Al igual que Black tengo problemas con el And y Or Negativos :P.

Utilizo 3 Array de Flags(bool) Para guardar los numeros y el resultado en binario.

Soporte para tipos de datos Dec, Hex, Oct y Bin.

Código
Private Function AndAlt(Byte1 As Long, Byte2 As Long) As Long
Dim bit1() As Boolean
Dim bit2() As Boolean
Dim bit3() As Boolean
Dim CT     As Long
Dim Tam    As Long
Dim b1     As Long
Dim b2     As Long
b1 = Byte1
b2 = Byte2
   Do
       ReDim Preserve bit1(CT)
       If b1 = 1 Then ReDim Preserve bit1(CT): bit1(CT) = True: Exit Do
       If b1 = 0 Then ReDim Preserve bit1(CT): Exit Do
       bit1(CT) = CBool(b1 Mod 2)
       b1 = Fix(b1 / 2)
       CT = CT + 1
   Loop
   CT = 0
   Do
       If b2 = 1 Then ReDim Preserve bit2(CT): bit2(CT) = True: Exit Do
       If b2 = 0 Then ReDim Preserve bit2(CT): Exit Do
       ReDim Preserve bit2(CT)
       bit2(CT) = CBool(b2 Mod 2)
       b2 = Fix(b2 / 2)
       CT = CT + 1
   Loop
   If UBound(bit1) > UBound(bit2) Then ReDim Preserve bit2(UBound(bit1))
   If UBound(bit1) < UBound(bit2) Then ReDim Preserve bit1(UBound(bit2))
   Tam = UBound(bit1)
   ReDim bit3(Tam)
   For X = 0 To Tam
       If bit1(X) Then If bit2(X) Then bit3(X) = True
   Next
   For X = 0 To Tam
       If bit3(X) Then AndAlt = AndAlt + 2 ^ (X)
   Next
 
End Function
 
Private Function OrAlt(Byte1 As Long, Byte2 As Long) As Long
Dim bit1() As Boolean
Dim bit2() As Boolean
Dim bit3() As Boolean
Dim CT     As Long
Dim Tam    As Long
Dim b1     As Long
Dim b2     As Long
b1 = Byte1
b2 = Byte2
   Do
       ReDim Preserve bit1(CT)
       If b1 = 1 Then ReDim Preserve bit1(CT): bit1(CT) = True: Exit Do
       If b1 = 0 Then ReDim Preserve bit1(CT): Exit Do
       bit1(CT) = CBool(b1 Mod 2)
       b1 = Fix(b1 / 2)
       CT = CT + 1
   Loop
   CT = 0
   Do
       If b2 = 1 Then ReDim Preserve bit2(CT): bit2(CT) = True: Exit Do
       If b2 = 0 Then ReDim Preserve bit2(CT): Exit Do
       ReDim Preserve bit2(CT)
       bit2(CT) = CBool(b2 Mod 2)
       b2 = Fix(b2 / 2)
       CT = CT + 1
   Loop
   If UBound(bit1) > UBound(bit2) Then ReDim Preserve bit2(UBound(bit1))
   If UBound(bit1) < UBound(bit2) Then ReDim Preserve bit1(UBound(bit2))
   Tam = UBound(bit1)
   ReDim bit3(Tam)
   For X = 0 To Tam
       If bit1(X) Then bit3(X) = True
       If bit2(X) Then bit3(X) = True
   Next
   For X = 0 To Tam
       If bit3(X) Then OrAlt = OrAlt + 2 ^ (X)
   Next
 
End Function
 
Private Function XorAlt(Byte1 As Long, Byte2 As Long) As Long
Dim bit1() As Boolean
Dim bit2() As Boolean
Dim bit3() As Boolean
Dim CT     As Long
Dim Tam    As Long
Dim b1     As Long
Dim b2     As Long
b1 = Byte1
b2 = Byte2
   Do
       ReDim Preserve bit1(CT)
       If b1 = 1 Then ReDim Preserve bit1(CT): bit1(CT) = True: Exit Do
       If b1 = 0 Then ReDim Preserve bit1(CT): Exit Do
       bit1(CT) = CBool(b1 Mod 2)
       b1 = Fix(b1 / 2)
       CT = CT + 1
   Loop
   CT = 0
   Do
       If b2 = 1 Then ReDim Preserve bit2(CT): bit2(CT) = True: Exit Do
       If b2 = 0 Then ReDim Preserve bit2(CT): Exit Do
       ReDim Preserve bit2(CT)
       bit2(CT) = CBool(b2 Mod 2)
       b2 = Fix(b2 / 2)
       CT = CT + 1
   Loop
   If UBound(bit1) > UBound(bit2) Then ReDim Preserve bit2(UBound(bit1))
   If UBound(bit1) < UBound(bit2) Then ReDim Preserve bit1(UBound(bit2))
   Tam = UBound(bit1)
   ReDim bit3(Tam)
   For X = 0 To Tam
       If bit1(X) Then If bit2(X) = False Then bit3(X) = True
       If bit2(X) Then If bit1(X) = False Then bit3(X) = True
   Next
   For X = 0 To Tam
       If bit3(X) Then XorAlt = XorAlt + 2 ^ (X)
   Next
 
End Function
 
Private Function NotAlt(Byte1 As Long) As Long
   NotAlt = -(Byte1 + 1)
End Function
 

GRACIAS POR LEER!!!

En línea

"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

 79137913                          *Shadow Scouts Team*                                                          Resumenes Cs.Economicas
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Comando de busqueda y reemplazo
GNU/Linux
Ole 3 461 Último mensaje 20 Septiembre 2006, 01:02
por Ole
ayuda con reemplazo integrado
Electrónica
juanxx 2 1,406 Último mensaje 27 Mayo 2007, 01:32
por GrTk
Reemplazo de Milw0rm ?
Hacking Básico
EvilGoblin 1 1,959 Último mensaje 15 Diciembre 2009, 16:49
por kamsky
Reemplazo de Memoria
Windows
mhoker 2 961 Último mensaje 13 Diciembre 2010, 07:00
por Randomize
[RETO] Reemplazo de Funcion IsNumeric « 1 2 3 4 »
Programación Visual Basic
79137913 46 3,453 Último mensaje 20 Agosto 2011, 03:29
por BlackZeroX (Astaroth)
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines