I get binary data from a file which is to be displayed in hex byte wise(i.e. 2 digits).
format$(hex(num),"00") places a leading zero for single digit numbers but it doesnot support for hex (A-F). How do i get leading zeroes for bytes of values A-F?
Is there any simplae way like format function rather compare and then pad '0' using left$?


regards,
Prathima

Recommended Answers

All 5 Replies

Use this solution:

IIf( hex(num) > 1, hex(num) , "0" & hex(num))

I tried

temp = IIf((Hex(Status) >= Hex(10) And Hex(Status) <= Hex(15)), "0" & Hex(Status), Hex(Status))
  ToFile = ToFile & Format$(temp, "00") & " "

But seems it works as string compare after conversion to hex.
For values like "C8" it returns "0C8". It returns evry value with A-F with a leading zero.
help pls,

Yes, finally i could make it. i compared it in decimal and then converted to hex

temp = IIf((num >= 10 And num <= 15), "0" & Hex(num), Hex(num))
        ToFile = ToFile & Format$(temp, "00")

let me know if you have any alternative

see this:

Thank you v much. It works out and is simple.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.