Converting a UPC number to Binary Follow
With RFID integration I have found that it is necessary to have Binary conversions of the decimal numbers. Part of the number string that is being encoded is the UPC number. A UPC number is a 12 digit number that is comprised of a Manufacturer ID (Usually 6 digits), an Item number or also known as a Product Code (Usually 5 digits) and a Check Digit. I found that a 12 digit number was too many numbers to successfully perform the Integer divide operation so I broke down the UPC number into a 6 digit Manufacturer ID and a 5 digit Product Code ( I don't need the check digit).
I recently looked up a video on Youtube that showed me a method that divides by 2 to calculate the conversion but it lays out the binary digits in reverse order. Luckily VB Scripting has a function called StrReverse() that will reverse the order of a string which was key in getting me the correct output. (The video is the what led me to use the Mod 2 and the integer divide by 2 operation "\2")
My question is, is there a way to do an integer divide of a 12 digit decimal number without having to break down the number into smaller components? (The EPC serial number is a 12 digit decimal number with a maximum value of 38 bit Binary.
My Code Sample:
' Define the varialbles for use in my script
Dim Dnum, Mnum, Inum, Bnum
' Initialize the variables to empty
' Set the variable Dnum to the starting decimal number to be converted to binary.
Dnum = Format.NamedSubStrings("Epcmfgid").Value ' Get the inital decimal number in this case the 6 digit UPC manufacturer ID from a named field in Bartender.
' Set the Dnum as the initial integer value for the division method
Inum = Dnum
Mnum = Inum Mod 2 ' Determine if the Inum devided by 2 will result in a fraction or an integer number.
Inum = Inum\2 ' Reset the Inum variable as the integer of the Inum variable divided by 2.
Bnum = Bnum & Mnum ' Concatenate the Mnum results in the Bnum variable until Inum is equal to 0
Loop Until Inum = 0 ' Loop until the integer number division operations reach 0 and exit the loop
Value = StrReverse(Bnum) ' Display the reverse order of the concatenated numbers from the calculations.
Please sign in to leave a comment.