Hexadecimal & Binary Numbers

For questions about using Classic.

Post » Fri Aug 31, 2012 2:47 am

is there a way operate in hex or binary numbers?

could this possibly be implemented?

for example hex() or could be used as an expression to define a number as hexadecimal, similar to int() or float(),
ie: hex(HHhhHH)

the same could be done for bin() or b() defining a number as binaryh(),
ie: bin(1010101010)

and for singed binaries as well, perhaps sbin() or sb()

if possible, it could also be very usefully extended to allow bitwise operations, such as bitwise AND, bitwise OR, bitwise XOR, and bitwise NOT.

and hey, maybe even include shifts and rotates.

i guess it could also be useful it they could be defined as nibbles [ nib() ], bytes [ byte() ], words [ wrd() / word() / w() ], dwords [ dword() / dw() ], and qword [ qword() / qw() ].

call me crazy, but i can definitely see the potential usefulness of this, especially when dealing with variables, and perhaps even saves, and colors.
i know binary files can be used already, but i dont think hex and binary numbers are operable with in construct, at least i looked for it and didnt find it was possible, nor did i find expressions for them, so i made the assumption that it is not yet implemented.

i'll admit i dont know how complicated this would be to implement, and if i could do it myself i would, but i'm gonna go out on a limb and guess it wouldnt be too difficult to include.

is there any possibility of this?

B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Fri Aug 31, 2012 4:39 am

It seems you are not aware of Yann's Bitwise Operations plugin?

It covers binary numbers and bitwise operations.

There's no hex plugin as far as I know, but you can create your own hex strings. Create an array with strings "0", "1", "2", ... "9", "A", "B", ..., "F"

For the conversion, use division, modulo, etc. For example, the number 31 would be "1F" as hex string. You'd get that result by int-dividing and subtracting:
firstdigit = int(number / 16) = 1
seconddigit = number - firstdigit * 16 = 15
Now just look at array(digits + 1) to compose your hex string:
myHex = array(firstdigit + 1) & array(seconddigit + 1) = "1F"

It's a very simple example, for 4-byte values it is a lot more dividing, subtracting, modulo, etc. And I'm not sure if it makes sense to convert them, but at least that's the principle.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Aug 31, 2012 9:42 am

wow, thanks for pointing that out, that slipped by me somehow.

too bad hex hasnt be implemented, though.
is that how you go about it?
i guess modulo and division is alright to go from hex to dec,
but if you convert dec to hex that way using strings you wouldnt be able to operate with them.
B
6
S
1
G
1
Posts: 52
Reputation: 858


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest