New topic: 

How to convert a string of binary nums(text) to Hex or Dec?

<http://forums.realsoftware.com/viewtopic.php?t=47960>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        tseyfarth          Post subject: How to convert a string of 
binary nums(text) to Hex or Dec?Posted: Thu May 23, 2013 6:59 pm                
         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 907                Hello All,

I have a string "11111111"  How do I convert this to a Hex or Decimal value?
Tim   
                             Top                charonn0          Post subject: 
Re: How to convert a string of binary nums(text) to Hex or DPosted: Thu May 23, 
2013 8:03 pm                                 
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1215
Location: San Francisco, CA, USA                Use Val and &b:

Dim s As String = "1111111"
Dim num As Integer = Val("&b" + s)


Then you can use the Hex or Str methods to turn the number into the hexadecimal 
or decimal representations:

s = Hex(num)
s = Str(num)
      
_________________
Boredom Software  
                             Top                languer          Post subject: 
Re: How to convert a string of binary nums(text) to Hex or DPosted: Thu May 23, 
2013 10:15 pm                         
Joined: Wed Feb 16, 2011 1:59 pm
Posts: 72
Location: Arizona, USA                Not sure if something like this works...

Function Hex2String(HexValue As UInt32, Bytes As UInt8) As String
'converts a 32-bit (4-byte) hex value into a string (MSB first)

Dim s As String
Dim msb As UInt8
Dim mb As New MemoryBlock(4)
mb.LittleEndian = False

If (Bytes > 0) And (Bytes < 5) Then
  msb = 4-Bytes
Else
  msb = 0
End If

mb.UInt32Value(0) = HexValue
s = mb.StringValue(msb,Bytes)
Return s
      
_________________
Windows XP SP3
RS 2012r2  
                             Top                tseyfarth          Post 
subject: Re: How to convert a string of binary nums(text) to Hex or DPosted: 
Thu May 23, 2013 11:14 pm                         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 907                Thanks guys!

I thought for sure there was  built in function, but I could not find one. 

Thanks again,
Tim   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to