Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Binary --> Hex and Vice versa also Binary --->Decimal
#11
Code:
Function bintohex( d As String ) As String
  
  Dim As String ret, foo, tmp
  Dim As Integer i, j
  
  foo = d
  
  Dim As zString Ptr hex_chars( 15 )=> _
    { _
      @"0", _  
      @"1", _  
      @"2", _  
      @"3", _  
      @"4", _  
      @"5", _  
      @"6", _  
      @"7", _  
      @"8", _  
      @"9", _  
      @"A", _  
      @"B", _  
      @"C", _  
      @"D", _  
      @"E", _  
      @"F" _
    }
  
  If ( Len( foo ) And 2 ) <> 0 Then
    foo = String( ( Len( foo ) And 2 ), Asc( "0" ) ) + foo
    
  
  End If
  
  
  For i = 0 To ( Len( foo ) \ 4 ) - 1
    
    For j = 0 To 3
      tmp += Chr( *cptr( Byte Ptr, @foo[( i * 4 ) + j] ) )
      
    Next

    tmp = "&B" & tmp
    ret += *hex_chars( Val( tmp ) )  
                        
    tmp = ""
              
  Next
  
  Return ret
    
End Function







  
  
  
? bintohex( "1010" &"1111" &"1110" &"0010" &"0010" & "0111" )

Sleep

freebasic only, they don't teach you that in school!!
Reply
#12
Cha0s,

This newbie is having problems with the fundamentals of QB programming, and you give him a hairy Freebasic function as a partial solution. Have a heart!
*****
Reply
#13
make up your mind, should i or shouldnt i give him simple working QB code, or should i give him something that's going to make him work a little..?
Reply
#14
Quote:make up your mind, should i or shouldnt i give him simple working QB code, or should i give him something that's going to make him work a little..?

I haven't been elected to make the decisions for this newbie, but IMHO "simple working QB code" would be best.

My particular dilema is how do I help him without actually writing all the code for him. Perhaps the best would be if he posted some code of his own, and we helped him make it work.

HYBRID, Are you listening?
Using Nathan's specs, take crack at writing one of your conversions. Then post your code.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)