shift integer by its full length? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kelvin8
Posts: 4
Joined: 21 Jun 2021, 02:52

shift integer by its full length?

Post by kelvin8 » 21 Jun 2021, 03:01

Hi

I have a program (.exe) which writes IDs to a file. These IDs are 10 digits number like 2216530427, 2216530426 - but somehow the program is buggy and instead I get - 2078436869, - 2078436870 which is exactly the length of the int (4294967296 ) minus the ID.

Now I`m searching for the most optimized way to fix these numbers. Instead of doing the arithmetic solution for every line which is the ID + 4294967296. I think bite shifting would be the most elegant way to fix this?

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: shift integer by its full length?

Post by Smile_ » 21 Jun 2021, 03:55

So if I understood correctly, you want to replace 2078436869 with 2216530427 by doing 4294967296-2078436869 and apply the same action to the rest of other IDs?
Could you give an example on how the file looks like?
Last edited by Smile_ on 21 Jun 2021, 03:57, edited 1 time in total.

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: shift integer by its full length?  Topic is solved

Post by SKAN » 21 Jun 2021, 03:56

Code: Select all

MsgBox %   (-2078436869 & 0xFFFFFFFF)
   . "`n"  (-2078436870 & 0xFFFFFFFF)
Edit:

Code: Select all

ID := -2078436869
ID &= 0xFFFFFFFF

MsgBox % ID

kelvin8
Posts: 4
Joined: 21 Jun 2021, 02:52

Re: shift integer by its full length?

Post by kelvin8 » 21 Jun 2021, 04:05

@SKAN Perfect!

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: shift integer by its full length?

Post by SKAN » 21 Jun 2021, 06:25

I'm extracting 32 bits from a 32 bit integer and in that process a signed number is getting converted to an unsigned integer.
I hope that makes sense.

An another approach.
I put a signed integer and get back an unsigned integer.

Code: Select all

VarSetCapacity(I,4)
MsgBox % NumGet(NumPut(-2078436869,I,"Int")-4,"UInt")

kelvin8
Posts: 4
Joined: 21 Jun 2021, 02:52

Re: shift integer by its full length?

Post by kelvin8 » 21 Jun 2021, 07:01

Now I understand

so the problem is that in my application the ID variable is signed int and it is out of range because the actual IDs are bigger than in example they start with 3x... so they out of signed int range that's why they get a negative sign -1x..

Now I wonder if its somehow possible to change the int declaration in my .exe application to unsigned int. That would be the best fix I think

Post Reply

Return to “Ask for Help (v1)”