| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Wed May 14, 2008 8:14 pm Post subject: Signed integer from BMP file |
|
|
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
|
Posted: Wed May 14, 2008 9:05 pm Post subject: |
|
|
a) use a nick
b) use a nick
c) SetFormat, Integer, Hex
d) use a nick |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 14, 2008 10:14 pm Post subject: |
|
|
| 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
|
Posted: Wed May 14, 2008 10:23 pm Post subject: |
|
|
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
|
Posted: Wed May 14, 2008 10:29 pm Post subject: |
|
|
| to lazy |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 14, 2008 11:04 pm Post subject: |
|
|
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 |
|
 |
|