Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert hex string to int in Crystal

Tags:

crystal-lang

I want to convert an hex string value in a variable to int.

This works for a literal: "#{0xFF}".to_i

But with a var...?

Not working test (interpolation error):

_myvar = "FF"
"#{0x_myvar}".to_i
like image 697
Mat Avatar asked Dec 25 '16 09:12

Mat


1 Answers

Why not check the API documentation for String

"FF".to_i(16)
like image 83
Oleh Prypin Avatar answered Sep 28 '22 11:09

Oleh Prypin