converting a string to bits in ruby, adding 1 bit and converting back to ascii -


I am writing Ruby UID generator and I need to generate unique IDs in fine order. Unique IDs are strings that differ from 3 to 9 characters.

What I want to achieve is this:

Get the ultimate-generated identifier, convert it to bits and 1 bit it (basically does a +1) and Converts the result back to ASCII. In this way, I can prevent a unique ID from being generated twice.

How can I do this in Ruby? I keep track of #pack and #pipe methods, but I can not understand in a way.

You can use something like this:

  A = "foobar" Unpack ("B *") [0] .to_i (2) +1   

= & gt; 77444424032627

  ["0" + a.to_s (2)] pack ("b *")   

= & gt; "Phobos"

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -