2's complement of Hexadecimal numbers
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
2's complement of Hexadecimal numbers
Hi All,
Did Livecode includes a function to calculate the
2's complement of an Hexadecimal number?
https://www.cs.cornell.edu/~tomf/notes/ ... scomp.html
Thanks in advance!
Al
Did Livecode includes a function to calculate the
2's complement of an Hexadecimal number?
https://www.cs.cornell.edu/~tomf/notes/ ... scomp.html
Thanks in advance!
Al
-
- VIP Livecode Opensource Backer
- Posts: 9835
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: 2's complement of Hexadecimal numbers
Seems useful for lower level computation, by what are the applications of such a function in a scripting language?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: 2's complement of Hexadecimal numbers
I will use this for calculating the negative height of BMP files.
https://stackoverflow.com/questions/373 ... age-in-hex
Mac OSX Preview and GIMP opens fine these BMP with
Transparency and negative Height.
https://drive.google.com/file/d/1XiBVh6 ... sp=sharing
EDIT: This code could work, but requires more testing:
https://stackoverflow.com/questions/373 ... age-in-hex
Mac OSX Preview and GIMP opens fine these BMP with
Transparency and negative Height.
https://drive.google.com/file/d/1XiBVh6 ... sp=sharing
EDIT: This code could work, but requires more testing:
Code: Select all
put baseconvert(((bitnot 326) + 1),10,16)
-
- VIP Livecode Opensource Backer
- Posts: 9835
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: 2's complement of Hexadecimal numbers
Curious. It hadn't occurred to me that an image format would use negative numbers. Thanks.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: 2's complement of Hexadecimal numbers
Hi.
Simple to write a function. With a field with a hex string and this in a button script:
Craig
EDIT.
Rewrote handler because I did not see at first the initial string was in hex.
Simple to write a function. With a field with a hex string and this in a button script:
Code: Select all
on mouseUp
get baseConvert(fld 1,16,2)
replace "0" with "x" in it
replace 1 with 0 in it
replace "x" with 1 in it
put baseConvert(it,2,10) into temp
answer baseConvert(temp + 1,10,2)
end mouseUp
EDIT.
Rewrote handler because I did not see at first the initial string was in hex.
Re: 2's complement of Hexadecimal numbers
Hi Craig,
Many Thanks for posting your script!
I ended up using this handler:
Many Thanks for posting your script!
I ended up using this handler:
Code: Select all
on mouseUp
put baseconvert(((bitnot fld 1) + 1),10,16)
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: 2's complement of Hexadecimal numbers
Hi.
Yes, "bitNot" reduces the number of lines required to, er, not the bits.
Craig
Yes, "bitNot" reduces the number of lines required to, er, not the bits.
Craig