Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Yet another feature request

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
dlh



Joined: 15 Dec 2006
Posts: 287
Location: ~Cincinnati

Posted: 29 April 2008, 20:49 PM    Post subject: Yet another feature request Reply with quote

It would be nice to have a CStrBin(var) to convert a variable to a binary string.
Back to top
stevech



Joined: 23 Feb 2006
Posts: 688

Posted: 30 April 2008, 3:59 AM    Post subject: Reply with quote

A binary ASCII string like "10101111" ?
pretty simple to code a function to do it.

rarely used?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 03 May 2008, 16:15 PM    Post subject: Reply with quote

stevech wrote:
pretty simple to code a function to do it.

Here's an example for Byte values that is written to be easily modified to handle 16-bit or 32-bit values.
Code:
Function CStrBinByte(ByVal val as Byte) as String
   Const bitCnt as Integer = SizeOf(val) * 8
   Dim buf(1 to bitCnt) as Byte
   Dim i as Integer
   For i = bitCnt to 1 Step -1
      buf(i) = IIF(CBool(LoByte(val) And 1), Asc("1"), Asc("0"))
      val = Shr(val, 1)
   Next i
   CStrBinByte = MakeString(buf.DataAddress, bitCnt)
End Function


Modified to handle Integer values:
Code:
Function CStrBinInt(ByVal val as Integer) as String
   Const bitCnt as Integer = SizeOf(val) * 8
   Dim buf(1 to bitCnt) as Byte
   Dim i as Integer
   For i = bitCnt to 1 Step -1
      buf(i) = IIF(CBool(LoByte(val) And 1), Asc("1"), Asc("0"))
      val = Shr(val, 1)
   Next i
   CStrBinInt = MakeString(buf.DataAddress, bitCnt)
End Function
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group