-1

Hey all I have the following 32 hexadecimal digit string:

0x80000000000000003F64000000000000

And when I need to take that number above and look up something with it I need it to be searchable in this type of format:

0000-0000-3F64-0000-S-0000-0000-R

The official format it needs to be in order to search is explained like this:

Format:

NNNN-NNNN-NNNN-NNNN-X
   or
NNNN-NNNN-NNNN-NNNN-X-NNNN-NNNN-Y
   or
NNNN-NNNN-NNNN-NNNN

where N are hexadecimal digits, X and Y are check digits.

16 hexadecimal digit followed with a check character (using Arabic numerals 0 to 9 and letters A to Z), followed by an 8 hexadecimal digit version segment, followed with a check character (using Arabic numerals 0 to 9 and letters A to Z).

Defined in ISO 15706-2 Annex D. The ISAN.

ROOT: 0000-0000-3F64

Tree segment of 4 digit hexadecimal values separated with a hyphen "-"

EpisodeOrPart: 0000

One segment of 4 digit hexadecimal values.

Check1: S

One digit made of a decimal value from 0 to 9 or an upper case charater from A to Z.

Version: 0000-0000

Two segments of 4 digits hexadecimal values separated with an hyphen "-".

Check2: R

One digit made of a decimal value from 0 to 9 or an upper case character from A to Z.

And I am not really sure how to go about converting what I have to the needed format so any help would be great!

Note: The "-S" and the "-R" can be removed. Those are random computer generated algorithms that add those which, as you see in the example above, are not needed in the search if you do not have them available. So really I would only be interested in getting the format to be "0000-0000-3F64-0000-0000-0000".

Community
  • 1
  • 1
StealthRT
  • 10,108
  • 40
  • 183
  • 342

2 Answers2

0

Not 100% sure what you want, but ...

This function removes the 0x from the beginning:

Private Function format(ByVal str As String) As String
    str = str.Substring(10)
    For i As Integer = 20 To 4 Step -4
        str = str.Insert(i, "-")
    Next
    Return str
End Function

Returns 0000-0000-3F64-0000-0000-0000 from 0x80000000000000003F64000000000000

For just 32 characters hex without the 0x prefix, this function:

Private Function format(ByVal str As String) As String
    str = str.Substring(8)
    For i As Integer = 20 To 4 Step -4
        str = str.Insert(i, "-")
    Next
    Return str
End Function

Returns 0000-0000-3F64-0000-0000-0000 from 80000000000000003F64000000000000

The Blue Dog
  • 2,475
  • 3
  • 19
  • 25
0

It's not at all clear what you want... where does the 8 go?

Here's is some code that may help...

'32 hex digits = 16 bytes (128 bits)'
Dim s As String = "0x80000000000000003F64000000000000" 
'simple reformat'
Dim s_sf As String = s.Substring(10, 4) & "-" & s.Substring(14, 4) & "-" & s.Substring(18, 4) & "-" & s.Substring(22, 4) & "-S-" & s.Substring(26, 4) & "-" & s.Substring(30, 4) & "-R"
MsgBox(s_sf)
'Convert hex string to byte 0x3F = 63 decimal
Dim b As Byte = Convert.ToByte("3F", 16)
MsgBox(b.ToString)
'Convert byte to Hex string 63 decimal = 0x3F
Dim s_hex As String = Hex(63)
MsgBox(s_hex)
SSS
  • 4,807
  • 1
  • 23
  • 44