ruby on rails 3 - Convert an alphanumeric string to integer format -
i need store alphanumeric string in integer column on 1 of models.
i have tried:
@result.each |i| hex_id = [] i["id"].split(//).each{|c| hex_id.push(c.hex)} hex_id = hex_id.join ... model.create(:origin_id => hex_id) ... end
when run in console using puts hex_id
in place of create line, returns correct values, above code results in origin_id being set "2147483647" every instance. example string input "t6gnk3pp86gg4sboh5oin5vr40" doesn't make sense me.
can tell me going wrong here or suggest better way store string aforementioned example unique integer?
thanks.
answering request form op
it seems hex_id.join
operation not concatenate strings in case instead sums or performs binary complement of hex values. issue hex_id
array of hex-es rather string, or char array. nevertheless, seems happen reaching maximum positive value integer type 2147483647
. still, unable find documented effects on array.join
applied on hex array, appears not concatenation of elements.
on other hand, desired result 060003008600401100500050040
large recorded integer either. better approach keep string, or use different algorithm producing number form original string. perhaps aggregating hex values arithmetic operation better join
?
Comments
Post a Comment