#1   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default dec2bin

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default dec2bin


dont be hasty when posting.. it just takes some time
for the post to filter thru...

see my answer to your first attempt!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default dec2bin

thanks, I never realised it was the same site, it appears totally different!

"keepITcool" wrote:


dont be hasty when posting.. it just takes some time
for the post to filter thru...

see my answer to your first attempt!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
.


  #4   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default dec2bin

thanks, how about bin to dec?

"keepITcool" wrote:


dont be hasty when posting.. it just takes some time
for the post to filter thru...

see my answer to your first attempt!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default dec2bin

Hi
reason for this is that you access the NG through a web interface and
not via a newsreader directly. Maybe check out:
http://www.mvps.org/dmcritchie/excel/xlnews.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"Jo" schrieb im Newsbeitrag
...
thanks, I never realised it was the same site, it appears totally

different!

"keepITcool" wrote:


dont be hasty when posting.. it just takes some time
for the post to filter thru...

see my answer to your first attempt!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default dec2bin


I've tried to make m complimentary to ATP's functions.

These work for (large) negative amounts too,

interpretation of negative binary strings <255 is always a gamble..
my rule is: negatives binTodec must have a lenght of multiple8 +2
(and start with 11)


Function DecToBin(ByVal Number As Long, Optional Places As Integer) As
String
Dim neg%, s$
neg = Number < 0
Number = Abs(Number) + neg
Do
s = (Number - neg) Mod 2 & s
Number = Number \ 2
Loop While Number 0

If Places < Len(s) Then
Places = Len(s)
End If
'Length s/b Multiple of 8
Places = Places - (Places - 1) Mod 8 + 7
s = String$(Places - Len(s), CStr(CInt(-neg))) & s
If neg Then
s = "11" & s
End If
DecToBin = s

End Function

Function BinToDec(ByVal BinString As String) As Long
Dim neg%, l&, i%, n%
n = Len(BinString)
neg = n 8 And n Mod 8 = 2
If neg Then
BinString = Mid(BinString, 3)
n = n - 2
End If
For i = 0 To n - 1
If Mid(BinString, n - i, 1) < CInt(-neg) Then
l = l + 2 ^ i
End If
Next
BinToDec = (neg - Not neg) * l + neg
End Function





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

thanks, how about bin to dec?

"keepITcool" wrote:


dont be hasty when posting.. it just takes some time
for the post to filter thru...

see my answer to your first attempt!

--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam



Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo
.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What 'value' is a Dec2Bin output? EvilTony Excel Discussion (Misc queries) 12 April 13th 09 01:59 PM
=Dec2bin can you increase the number bits please WAT Excel Discussion (Misc queries) 0 July 29th 06 01:20 AM
How to get leading zeros using DEC2BIN scallyte Excel Worksheet Functions 2 December 8th 05 11:52 PM
Base number functions, example DEC2BIN Wayne Boswell via OfficeKB.com Setting up and Configuration of Excel 0 February 24th 05 04:18 AM
dec2bin Jo[_6_] Excel Programming 1 November 9th 04 04:47 PM


All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"