Jump to content

BitAnd


Mpro
 Share

Recommended Posts

Hi! AutoIt developper!

Here's the bug!

The result of this BitAND in AutoIt is -338845696

$Temp = BitAND(3667563225088, 0xFFFFFFFF)

The result is supposed to be = 3956121600

How to explain this result! 1st number too big?:mellow:

How calculate this number?

Thanks !!!!!!!!

Link to comment
Share on other sites

Hi! AutoIt developper!

Here's the bug!

The result of this BitAND in AutoIt is -338845696

$Temp = BitAND(3667563225088, 0xFFFFFFFF)

The result is supposed to be = 3956121600

How to explain this result! 1st number too big?:mellow:

How calculate this number?

Thanks !!!!!!!!

Wouldn't that be the same as

ConsoleWrite(Mod(3667563225088,2^32 - 1) & @CRLF)

?

But that gives 3956122453 not 3956121600

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Wouldn't that be the same as

ConsoleWrite(Mod(3667563225088,2^32 - 1) & @CRLF)

?

But that gives 3956122453 not 3956121600

EDIT:second thoughts maybe it should be

ConsoleWrite(Mod(3667563225088,2^32 - 1) - int(3667563225088/(2^32 - 1)) & @CRLF)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You can do some 64-bit arithmetic using that kludge. You may as well code them with "AutoIt assembler" to get rid of dependency.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Why?

Could it be Mod(3667563225088, 2^32)?

I don't think that is correct because there could be a multiple of 2^32 in the number and that will add to the value from Mod.

Eg

supposing X is less than 2^32 then

Mod(X + 5*(2^32),2^32) = BitAnd(X + 5*(2^32),2^32) + 5

My logic, or lack of it, was like this

BitAnd(16,15) = 0

Mod(16,15) = 1

So I thought that

Mod(A,G) = BitAnd(A,G) + Int(A/G)

EDIT:

Here it is a bit better.

Any number can be written as the sum of 2 numbers like this

D = N + G*K

where N < K and k is 2^p with p any value you like.

BitAnd(D,K-1) is going to be N.

Mod(D,K) = Mod(N + G*K,K)= Mod(Mod(N/K,G) + G),K)=N+G

So

N = Mod(D,K) - G

and G is Int (D/K) Therefore

BitAnd(D,K-1) = Mod(D,K) - Int(D/K)

So now I'm happy that I'm right.

I think I'm happy but I'll check tomorrow.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@Mpro:

If you have repetitive use of such ops, try the small 64-bit code I mentionned above.

@Martin: Hi,

No, your result will be 1 over. Mod(X, Y) returns a result 0 <= Z < Y in all cases. AND 0x00..FF..FF mask won't touch LSB.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@Martin: Hi,

No, your result will be 1 over. Mod(X, Y) returns a result 0 <= Z < Y in all cases. AND 0x00..FF..FF mask won't touch LSB.

Hi jchd,

That makes no sense to me! Are you thinking of Div.

I modified my previous post but if you can see an error in my logic please show me what it is.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I don't think that is correct because there could be a multiple of 2^32 in the number and that will add to the value from Mod.

...

Mod(D,K) = Mod(N + G*K,K)= Mod(Mod(N/K,G) + G),K)=N+G

It's there!

By definition of Mod, G*K = 0 mod(K)

So Mod(N + G*K, K) = N , assuming as you did that N < K.

In other words the remainder of the [euclidean] division of kX by X is 0, given X <> 0.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

It's there!

By definition of Mod, G*K = 0 mod(K)

So Mod(N + G*K, K) = N , assuming as you did that N < K.

In other words the remainder of the [euclidean] division of kX by X is 0, given X <> 0.

I would be surprised if I what I said made sense since my posts last night were hours after I had intended to go to bed.

I think I was thinking that the divisor in Mod was the value to be Anded but it is 1 more obviously. Who knows? Anyway, I was talking bollocks.

Euclidean division? Is that like a Roman division?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Too big, too small, - size doesn't matter after all:

#include <string.au3>

MsgBox(0, "Custom BitAnd", _BitAnd(3667563225088, 4294967295));  0xFFFFFFFF = 4294967295

;MsgBox(0, "standard", BitAND(134, 172))

Func _BitAnd($arg1,$arg2)
    Local $bin = "", $bin2 = "", $result = ""


While($arg1 >= 1)
    $arg1 /= 2
    If StringIsDigit($arg1) Then
        $bin &= 0
    Else
        $split = StringSplit($arg1, ".")
        $arg1 = $split[1]
        $bin &= 1
    EndIf
WEnd

While($arg2 >= 1)
    $arg2 /= 2
    If StringIsDigit($arg2) Then
        $bin2 &= 0
    Else
        $split = StringSplit($arg2, ".")
        $arg2 = $split[1]
        $bin2 &= 1
    EndIf
WEnd


$bin = _StringReverse($bin)
$bin2 = _StringReverse($bin2)

If StringLen($bin) <> StringLen($bin2) Then
    If StringLen($bin) > StringLen($bin2) Then
        $add =""
        For $i = 1 To (StringLen($bin) - StringLen($bin2)) Step 1
            $add  &= 0
        Next
        $bin2 = $add & $bin2
    Else
        $add = ""
        For $i = 1 To (StringLen($bin2) - StringLen($bin)) Step 1
            $add  &= 0
        Next
        $bin = $add & $bin
    EndIf

EndIf

$split1 = StringSplit($bin,"")
$split2 = StringSplit($bin2,"")
For $i = 1 To StringLen($bin) Step 1
    If $split1[$i] = 0  Or $split2[$i] = 0 Then
        $result &= 0
    ElseIf $split1[$i] = $split2[$i] And $split1[$i] = 1 Then
        $result &= 1
    EndIf
Next


$split = StringSplit($result, "")

$x = $split[1]
For $i = 1 To StringLen($result)-1 Step 1
    $x = $x * 2 + $split[$i+1]
Next
$result = $x
Return $result
EndFunc

:mellow:

Edited by Godless

_____________________________________________________________________________

Link to comment
Share on other sites

Euclidean division? Is that like a Roman division?

Just like you learnt it as a kid, remember, long, long ago ;-) and just before they thaught you this shitty decimal point.

A = B * Q + R with A::dividend, B::divisor, Q::quotient, R::remainder and A, Q ∊ ℤ, B ∊ ℤ*, R ∊ ℕ, R < |Q|

Probably the first equation with two unknowns that one encounters.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...