Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help wit LONG hex number conversion
#11
Neo:
I just got back in and was able to look at the program. Maybe I am wrong, but it looks like the OPPOSITE of what I need. I ALREADY have the 96 bit BINARY rfid number, what I need is to convert the 96 BINARY that I have created in my own program into hex to be used in a seperate routine.
If it helps, the original I created is a 96 bit binary, however, the 36 most significant bits are not changed, so I CAN get by with just the rightmost 58 digits being converted to hex
Ralph:
As for using the windows calculator, it will convert a number from one base to another, but it wont create the 96 bit binary from the required fields. Again, I have already written the program to generate the binary, I need to convert the binary to hex, and have it incorporated into the existing program.
Reply
#12
If you have a binary string of any length (multiple of 8, which indicates a round number of bytes), you can do the following.

Code:
' This is an example of a 96-bit binary string
MyBinaryString$ = "011000001101001000001100000000001110010100000001000000000000000001111111000110110110001100000101"

' Empty hex string
MyHexString$ = ""

' Loop all bytes of it
For byteLoop = 0 To (Len(MyBinaryString$) - 1) Step 8
  ' new variable
  TempStorage% = 0
  ' loop all 8 fields
  For fieldLoop = 7 To 0 Step -1
    TempStorage% = TempStorage% OR ((2 ^ (fieldLoop)) * VAL(MID$(MyBinaryString$, byteLoop + 8 - fieldLoop, 1)))
  Next fieldLoop
  ' attach to the hex string
  MyHexString$ = MyHexString$ + RIGHT$("00" + HEX$(TempStorage%), 2)
Next byteLoop

' print out the hex string
PRINT MyHexString$

It isn't the fastest code existing, but it works.
Program output:
Quote:60D20C00E50100007F1B6305
Which is exactly what the previous program outputted.

Hope this helped some more =),

Neo
Reply
#13
BornLoser:
Sorry, after going back and trying the Windows Calculator, I see that it is limited to 16 digits in Decimal notation, so, it's fine only for integer up to that size only, and, as you pointed out, no good for your problem.

So, I surfed the Internet, as I knew there was a good calculator for large numbers, and, I found one! I tried it with 39 decimal intgers, converted to binary, to hex, and back, all worked fine!

The program in called BigCalc.exe, is only 600+ KB, and can be downloaded from:

http://www.bigcalc.scriptmania.com/

Does this help?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)