ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   dec2bin (https://www.excelbanter.com/excel-programming/316206-dec2bin.html)

Jo

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
..



keepITcool

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
.


Jo

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
.



Jo

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
.



Frank Kabel

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
.




keepITcool

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
.




All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com