Page 1 of 1

Ruby String to Hex <-> Hex to string

Posted: Fri Jun 08, 2012 2:21 pm
by CoreStylerz
Hi all.
Im newbie on Flowstone forum but i own synthmaker. i need to something in ruby code with flowstone for a prototype of a web application with ruby.
The problem is that i get different values with ruby. I need to generate the exactly same result of maths. but i have troubles with hex-string string-hex conversion, that does not gave me the same of flowstone.
Ruby s2h.PNG
Ruby s2h.PNG (13.58 KiB) Viewed 22337 times


As you can see, the primitive string to hex give me 4343314435303937 from CC1D5097.
Ruby instead give 3424473239.

Someone can explain why, and a solution of this trouble?
And how to to hex to dec in ruby component?

Re: Ruby String to Hex <-> Hex to string

Posted: Fri Jun 08, 2012 3:55 pm
by Embedded
It is your FlowStone code that isn't correct, the Ruby is right.

Ruby Hex.png
Ruby Hex.png (17.01 KiB) Viewed 22334 times

Re: Ruby String to Hex <-> Hex to string

Posted: Fri Jun 08, 2012 8:57 pm
by CoreStylerz
No. because if i do the same as you i continue to get the same integer value.
ruby.PNG
ruby.PNG (15.73 KiB) Viewed 22332 times

And i don't want to use internal flowstone primitives because i already have the app created with synthmaker ( same or similar core of flowstone) and i wish to make all in internal ruby component to make a further web app. (for registering software products... challenge-response).

If flowstone/synthmaker conversion not work as it should, there are any workaround to make it 100% stable?

I tried this website http://www.string-functions.com/string-hex.aspx it convert the sting exactly like flowstone.
Seems ruby that corrupt this.
infact
CC1D5097 = 4343314435303937

and...
i tried ruby terminal... always say 3424473239.
So maybe is ruby problem or need some things that actually i dont know.. (i started ruby yesterday.. 100% newbie :roll: )
command was

Code: Select all

mac = "CC1D5097"
mac.hex
=>3424473239

Re: Ruby String to Hex <-> Hex to string

Posted: Sun Jun 10, 2012 6:37 am
by Embedded
Maybe we are talking at cross purposes, what is it exactly you are trying to do?

a) Convert a string of chars to hex (eg. Hello World = 48656C6C6F20576F726C64)
b) Convert a Hex number into a decimal number eg. CC1D5097 = -870494057)

In FlowStone you are using the Char String to Hex NOT the Hex String to INT module (As I did in the project I posted)

The website you posted is also Chars to hex not Hex to Int.

The Ruby code you used works (.hex or .to_i(16)) but outputs unsigned Ints that can exceed the 32 bit Max int value in FS. Yours works as a 32 bit signed number so there is a little work in Ruby to create a 32bit signed Int:

Ruby Hex clip.png
Ruby Hex clip.png (58.59 KiB) Viewed 22312 times


For more info on binary number systems and 2's compliment visit: http://en.wikipedia.org/wiki/Twos_complement

Re: Ruby String to Hex <-> Hex to string

Posted: Sun Jun 10, 2012 1:25 pm
by CoreStylerz
I need to pass string to hex string. then hex to dec and finally string to int with the sign.

Re: Ruby String to Hex <-> Hex to string

Posted: Mon Jun 11, 2012 1:52 pm
by Embedded
So Ruby and FlowStone are working correctly, your number system just exceeds the number system allowed on a PC running a 32 bit app.

If CC1D5097 is a string of chars then the Hex = 0x4343314435303937 = a 64 bit number, so you can't just convert it into an Integer as it exceeds the range of the number system.

Here's a new Ruby example of ASCII String to Hex String to Int, that works as long as the result is a 32 bit signed number or less.