• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Math question - Hexadecimal

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
for this example i use hexadecimal but i guess this same to every higher than 10 based numbers:

so i want do this:
have 2 hexadecimal number (but saved in string like: 0A,5F): x, y
have a integer number c
have a string s

JASS:
x = "*random hexadecimal number like: AF or 045D or 013E45*"
Y = "*random hexadecimal number like: E0 or 31C2 or 205315*"

a = StringLength(x) //could be 1-4
b = StringLength(y) //could be 1-4

//if the 2 hexadecimal number stringlength not same then save a number before the x,y
if a != b then 
   set c = a*10+b
   set s = I2S(c)+x+y  
   //i dont want write how but 'c' number will be 1 charater only like A=a*2+3=23
else
   set s = x + y          
  //so could be 0A + BC => 0ABC or 0C5432 + 870EAE => 0C5432870EAE
  //length is between 1-4
endif

question is if i know the s in another function then i am able to know it is c+x+y or only x+y?
both way the 's' stringlength is paired number so 2 or 4 or 6 or 8.
i would check the first character value and convert to number example will be 23 and let say 's' string length was 6, so left theoretical 1st character could be c but same time could be part of the following number too (the hexadecimal string: 'x')

so i am able detect its part of the 'x' or it was 'c'?
 
Last edited:

sentrywiz

S

sentrywiz

Your question is explained in a complex manner. It barely makes sense, and I lost track what exactly is your question. Maybe you should simplify it, both for you and the reader.

Also, why hexadecimal?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Your question is explained in a complex manner. It barely makes sense, and I lost track what exactly is your question. Maybe you should simplify it, both for you and the reader.

Also, why hexadecimal?

indifferent if hexadecimal or 64base string, i guess its work same way with any 10+ based numbers, i just want figure out if i able store then unpack 2 higher based number near eachother without delimiter (like "-") if the 2 number got same string length
 
There may be cases when you can, but that depends entirely on the context of the situation.

If you're given arbitrary hex strings and are trying unpack the values, you can't necessarily know the length without more info. Let's say you have a situation where the resulting string is 6 characters. On one hand, it could be that the hex X and Y were length 3 each. Or it could be that X was 2 and Y was 3, and then 1 character 'c' was added. Or it could be X = 3, Y = 2, and 1 character 'c' was added. Without any additional information or context to the problem, it is impossible to unpack the hex and determine which values represented X and which values represented Y.

As such, how do you solve this? There are many ways. The most intuitive way is to encode the first two chars to represent the length of X and Y respectively. So if you had:
X = 04F, Y = 3AFD, then the result would be "3404F3AFD", where "34" represents "3" as the X-length, and "4" as the y-length.

Another way could be to reserve characters. Reserve the first char for all the possible addition combinations.
A = 1 + 1 , E = 2 + 1 , I = 3 + 1 , M = 4 + 1
B = 1 + 2 , F = 2 + 2 , J = 3 + 2 , N = 4 + 2
C = 1 + 3 , G = 2 + 3 , K = 3 + 3 , O = 4 + 3
D = 1 + 4 , H = 2 + 4 , L = 3 + 4 , P = 4 + 4
This table is nice and neat, and it covers all possible length combinations of X and Y. Why do this? It saves a character. So in the example above, you have:
X = 04F, Y = 3AFD, and the result would be "L04F3AFD". In your code, you would detect that the first char is "L" and instantly know that X is of length 3 and Y is of length 4, because L represents the combination 3 + 4.

There are other options too, but you consciously need to place some boundaries, or you have to use an extra character, in order to unpack X and Y and know their respective lengths.
 
Level 12
Joined
Oct 16, 2010
Messages
680
if the goal is the need of as less characters as could be, a fine way to do it is by resizing one of the strings to match the longer

example: X=A4 Y=4F9 ---> Set X= 0A4 ---> s = 0A44F9

never will require more then 8 chars and u know X and y are always match in length

you sad these are numbers stored as string so converting back won't be a problem with the extra zeros.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
There may be cases when you can, but that depends entirely on the context of the situation.

If you're given arbitrary hex strings and are trying unpack the values, you can't necessarily know the length without more info. Let's say you have a situation where the resulting string is 6 characters. On one hand, it could be that the hex X and Y were length 3 each. Or it could be that X was 2 and Y was 3, and then 1 character 'c' was added. Or it could be X = 3, Y = 2, and 1 character 'c' was added. Without any additional information or context to the problem, it is impossible to unpack the hex and determine which values represented X and which values represented Y.

As such, how do you solve this? There are many ways. The most intuitive way is to encode the first two chars to represent the length of X and Y respectively. So if you had:
X = 04F, Y = 3AFD, then the result would be "3404F3AFD", where "34" represents "3" as the X-length, and "4" as the y-length.

Another way could be to reserve characters. Reserve the first char for all the possible addition combinations.
A = 1 + 1 , E = 2 + 1 , I = 3 + 1 , M = 4 + 1
B = 1 + 2 , F = 2 + 2 , J = 3 + 2 , N = 4 + 2
C = 1 + 3 , G = 2 + 3 , K = 3 + 3 , O = 4 + 3
D = 1 + 4 , H = 2 + 4 , L = 3 + 4 , P = 4 + 4
This table is nice and neat, and it covers all possible length combinations of X and Y. Why do this? It saves a character. So in the example above, you have:
X = 04F, Y = 3AFD, and the result would be "L04F3AFD". In your code, you would detect that the first char is "L" and instantly know that X is of length 3 and Y is of length 4, because L represents the combination 3 + 4.

There are other options too, but you consciously need to place some boundaries, or you have to use an extra character, in order to unpack X and Y and know their respective lengths.

the table is nice but how still not got how can i know if it is 1table char+3+4 or 4+4?

btw this was the closest to what i wanted but at end i thought better if i just use array and string for this

http://www.hiveworkshop.com/forums/...s-1-24-a-257261/?prev=d=list&r=20&u=shadowvzs

there could you check the triggers? i tryed save with 1 character more than 2 number length, what is the opinion?
i wanted make not fixed 8 length long even if 2 value lets say only 1-1
 
Status
Not open for further replies.
Top