Hexadecimal & Binary Numbers

This forum is currently in read-only mode.
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • 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?

    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)