Jump to content

unsigned bit shift


Recommended Posts

I'm trying to turn on the MSB in an autoit int using the following logic:

11111 (Starting with a -1)

01111 (Shift right one)

10000 (not)

The problem (my problem) is that autoit does a logic shift for the number as a signed number and thus I endup with -1 again. Is there a way to tell the shift that the number is unsigned?

Here is my test code

Local $L_iRc = 0
$L_iRc = BitNOT($L_iRc)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console 
$L_iRc = BitShift( $L_iRc , 1 )
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$L_iRc = BitNOT($L_iRc)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

Also is there a way to get the size of a number in autoit?

Thanks!

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

AutoIt int type is signed. Get over it. Unsigned "uint" for AutoIt only exists in DLL structs.

I don't see why you want derive this through shifting, but you could do this:

Local $L_iRc = 0x40000000
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @CRLF & '>Error code: ' & @error & @CRLF & @CRLF) ;### Debug Console
$L_iRc = BitShift($L_iRc, -1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @CRLF & '>Error code: ' & @error & @CRLF & @CRLF) ;### Debug Console

...or this:

Local $L_iRc = 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @CRLF & '>Error code: ' & @error & @CRLF & @CRLF) ;### Debug Console
$L_iRc = BitRotate($L_iRc, -1, "D")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $L_iRc = ' & $L_iRc & @CRLF & '>Error code: ' & @error & @CRLF & @CRLF) ;### Debug Console

The result either way is 0x80000000 binary (MSB set), which is -2147483648 as a signed int.

:idea:

P.S. What does "size of a number" mean? Maybe Abs()?

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

LOL.... or this:

$z = BitShift( 1, -31)

That was from the help file...

I just wanted to know how many bytes my number was occupying so I'll be able to know which bit to turn on. The help file had the answer... 32 bit!

Thanks for the help man, I'll be using BitRotate($L_iRc, -1, "D")

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

AFAICT the current state of affairs is that AutoIt integers are 64-bit signed ints but hexadecimal and bit operations (the 0x..., Hex, Bit* functions) only operate on 32-bit ints.

That makes the answer to your last question less than precise. You can still perform calculations on 64-bit ints:

ConsoleWrite(0x12345678 * 1024 * 1024 * 1024 & @LF) ; clearly more than 32-bit integer

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

The type dynamically changes:

$iVal = 0x12345678
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)
$iVal *= 1024 * 1024 * 1024
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Unfortunately, it won't automatically switch to floating point:

$iVal = 0x12345678
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)
$iVal *= 1024 * 1024 * 1024
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)
$iVal *= 1024 * 1024 * 1024
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF) ; <== $iVal = -9223372036854775808; Type = Int64

Forcing float prevents that:

$iVal = 0x12345678
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)
$iVal *= 1024 * 1024 * 1024
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)

$iVal *= 1.00 * 1024 * 1024 * 1024
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF) ; <==  $iVal = 3.52125166033187e+026; Type = Double

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...