Based on this comment that you added:
long.Parse(string.Concat(DId, BId, DocId, OpId))
length of DId = 8 length of BId = 5 length of DocId = 7 length of OpId = 4
And assuming that what you have said means:
length of DId = 8 Value = 0 to 99,999,999 (up to 27 bits)
length of BId = 5 Value = 0 to 99,999 (up to 17 bits)
length of DocId = 7 Value = 0 to 9,999,999 (up to 24 bits)
length of OpId = 4 Value = 0 to 9,999 (up to 14 bits)
You need a total of 82-bits to guarantee that a unique value can be generated from the four source values.
That is too long to be stored in a long
, which has a maximum storage capacity of 64-bits.
If, however, what you meant was that the bits for each value were as you indicated:
length of DId = 8 BITS Value = 0 to 255
length of BId = 5 BITS Value = 0 to 31
length of DocId = 7 BITS Value = 0 to 127
length of OpId = 4 BITS Value = 0 to 15
Then you could store this in a long as the total size is only 24-bits.
You could do this by using bit shifting:
long Id = (long)((DId << 16) + (BId << 11) + (DocId << 4) + OpId);