Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Ruby String to Hex <-> Hex to string

For general discussion related FlowStone

Ruby String to Hex <-> Hex to string

Postby CoreStylerz » Fri Jun 08, 2012 2:21 pm

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 20732 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?
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
User avatar
CoreStylerz
 
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy

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

Postby Embedded » Fri Jun 08, 2012 3:55 pm

It is your FlowStone code that isn't correct, the Ruby is right.

Ruby Hex.png
Ruby Hex.png (17.01 KiB) Viewed 20729 times
Attachments
Ruby Hex.fsm
(321 Bytes) Downloaded 1172 times
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

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

Postby CoreStylerz » Fri Jun 08, 2012 8:57 pm

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 20727 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
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
User avatar
CoreStylerz
 
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy

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

Postby Embedded » Sun Jun 10, 2012 6:37 am

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 20707 times


For more info on binary number systems and 2's compliment visit: http://en.wikipedia.org/wiki/Twos_complement
Attachments
Ruby Hex.fsm
(3.52 KiB) Downloaded 1123 times
Last edited by Embedded on Mon Jun 11, 2012 1:55 pm, edited 1 time in total.
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

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

Postby CoreStylerz » Sun Jun 10, 2012 1:25 pm

I need to pass string to hex string. then hex to dec and finally string to int with the sign.
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
User avatar
CoreStylerz
 
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy

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

Postby Embedded » Mon Jun 11, 2012 1:52 pm

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.
Attachments
Ruby Hex3.fsm
(3.65 KiB) Downloaded 1146 times
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm


Return to General

Who is online

Users browsing this forum: No registered users and 75 guests