I was working on the dbsnp bitfield recently in javascript for a custom jbrowse implementation, and what I realized is that this isn't a true bitfield. It's actually 24 characters long, containing 12 different bitfields, each 2 character chunk corresponding to a byte encoded as hex. Therefore, I made a very similar answer to the python answer above, but I thought I'd just reiterate that for anyone in the future:
var ncbi_encoding=parseInt(name.substr(0,2),16);
var ncbi_links_1=parseInt(name.substr(2,2),16);
var ncbi_links_2=parseInt(name.substr(4,2),16);
var gene_function1=parseInt(name.substr(6,2),16);
var gene_function2=parseInt(name.substr(8,2),16);
var mapping=parseInt(name.substr(10,2),16);
var frequency=parseInt(name.substr(12,2),16);
var genotype=parseInt(name.substr(14,2),16);
var hapmap=parseInt(name.substr(16,2),16);
var phenotype=parseInt(name.substr(18,2),16);
var var_class=parseInt(name.substr(20,2),16);
var quality=parseInt(name.substr(22,2),16);
Edit 2014-08-19: I did not need to reverse bits as I originally posted. You can just use regular "numerical" bit operations on the variables above. The python answer above converts the variables into an 8 character string in bytesArray so for example, bytesArray[0] would be a string of length 8 representing binary bits going from left to right (which is pretty unnatural IMO). In mine, but you can just instead use bitwise operations on the variables in my answer.
For example, in the python answer for the VP string 050060000a01000002110100
, you get
bytesArray= ['10100000', '00000000', '00000110', '00000000', '01010000', '10000000', '00000000', '00000000', '01000000', '10001000', '10000000', '00000000']
In mine, you have
[ncbi_encoding, ncbi_links_1, ncbi_links_2, gene_function1, gene_function2, mapping, frequency, genotype, hapmap, phenotype, var_class, quality]
which is
[5, 0, 96, 0, 10, 1, 0, 0, 2, 17, 1, 0]
I don't understand why you're reversing the bin representation of each field. Did you find that documented somewhere?
I also wonder why the answer's author feels the need to reverse the bits. My best guess is that he is unfamiliar with the convention that, these days, bit ordering is typically most significant bit first. This is the convention followed in Python; for example, try
This is why, in the PDFs linked here, the bits are indexed in decreasing order from top to bottom (a 90-degree rotation of how they would be indexed from right to left). I can see how this would be confusing, and dbSNP should provide more explicit documentation.