AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Signed integer from BMP file

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed May 14, 2008 8:14 pm    Post subject: Signed integer from BMP file Reply with quote

Using the BinRead function posted by Laszlo I read the header of a bmp file. The only thing I'm having trouble with is figuring out how to convert the several strings of hex into signed integers.

For example, I know 28000000 should somehow turn into 40 (file header size in bytes) and 76010000 should turn into 374 (file size in bytes). I just don't know how to convert the numbers
Back to top
BoBo²
Guest





PostPosted: Wed May 14, 2008 9:05 pm    Post subject: Reply with quote

a) use a nick
b) use a nick
c) SetFormat, Integer, Hex
d) use a nick
Back to top
Guest






PostPosted: Wed May 14, 2008 10:14 pm    Post subject: Reply with quote

BoBo² wrote:
a) use a nick
b) use a nick
c) SetFormat, Integer, Hex
d) use a nick


a) too lazy
b) too lazy
c) It's in hex, I need to convert it to a signed integer not a number in base 10
d) too lazy
Back to top
Guest






PostPosted: Wed May 14, 2008 10:23 pm    Post subject: Reply with quote

Okay, to prevent any more confusion, rather than post the numbers in hex here they are in binary. I posted them in hex because that's what the BinRead() function gave me...

I need to change the binary number into a signed integer, these binary numbers are what I got from a bitmap file.

00101000000000000000000000000000 needs to turn into 00101000 (40)
01110110000000010000000000000000 needs to turn into 000101110110 (374)
Back to top
Guest






PostPosted: Wed May 14, 2008 10:29 pm    Post subject: Reply with quote

to lazy
Back to top
Guest






PostPosted: Wed May 14, 2008 11:04 pm    Post subject: Reply with quote

Okay figured it out... these two functions seem to do everything I need
Code:

; Takes hex, returns digit
SignInt(HEX)
{
   If (StrLen(Hex)/2 != StrLen(Hex)//2)
      Return 0
   Hex := "0x" . Hex
   Hex += 0
   Return % Hex >> 24
}
; Takes digit, returns hex
ToSignInt(Num)
{
   TempFormat := A_FormatInteger
   SetFormat,Integer,H
   Num += 0
   Return % (StrLen(Num << 24)/2 != StrLen(Num << 24)//2 ? "0" : "") . RegExReplace(Num << 24,"^0x")
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group