Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2003, 10:39 AM
m0dr0cker m0dr0cker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 118 m0dr0cker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Excel decimal to binary (32 bit) conversion

Hi guys. I'm trying to write an Excel function that will take a 32 bit integer and calculate its binary equivalence, however I have very little experience with VisualBasic and was wondering if somebody could give me an idea of how I'd go about doing this.

Thanks.

Reply With Quote
  #2  
Old October 9th, 2003, 12:38 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,982 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 18 h 42 m 27 sec
Reputation Power: 814
I've not tried something like this, but one way that comes to mind (untried) is to use the hex function on the number and parse the resulting hex characters in the string, and build a new string with the binary equivalent of the hex characters.

Reply With Quote
  #3  
Old October 9th, 2003, 02:51 PM
m0dr0cker m0dr0cker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 118 m0dr0cker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
That's exactly what I wound up doing, and I have this really long string of Excel commands daisy-chained together which will give me what I want, and it works.

But you have to change two numbers within that very long chain of commands depending on which bit of the 32 bit integer you want to look at.

Right now I've opened up the VB editor in Excel and have written the following code in a new module:

Code:

Function BitState(Value As Long, Bit As Integer)
    
    Dim Y As Integer
    Dim Z As Integer
    
    If ((Bit >= 0) And (Bit <= 3)) Then
        Y = 1
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 4) And (Bit <= 7)) Then
        Y = 2
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 8) And (Bit <= 11)) Then
        Y = 3
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 12) And (Bit <= 15)) Then
        Y = 4
        Z = (Bit Mod 4) + 1
    End If

    If ((Bit >= 16) And (Bit <= 19)) Then
        Y = 5
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 20) And (Bit <= 23)) Then
        Y = 6
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 24) And (Bit <= 27)) Then
        Y = 7
        Z = (Bit Mod 4) + 1
    End If
    
    If ((Bit >= 28) And (Bit <= 31)) Then
        Y = 8
        Z = (Bit Mod 4) + 1
    End If
    
    BitState = Left(Right(HEX2BIN(Left(Right(DEC2HEX(Value, 8), Y)), 4), Z))
    
End Function


But when I try to compile it, I get this:

"Compile Error: Sub or Function Undefined" and it highlights the "DEC2HEX" function. I thought you could use Excel standard macros within my function.

So I'm stuck here. I don't know what to do.

Last edited by m0dr0cker : October 9th, 2003 at 02:53 PM.

Reply With Quote
  #4  
Old October 9th, 2003, 11:40 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Try to Use hex function to replace the DEC2HEX function..

Reply With Quote
  #5  
Old October 10th, 2003, 08:01 AM
m0dr0cker m0dr0cker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 118 m0dr0cker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I can't find any help on the hex function in Excel.

Reply With Quote
  #6  
Old October 10th, 2003, 02:21 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,982 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 18 h 42 m 27 sec
Reputation Power: 814
In Excel 2000, open the Help table of contents (I'm not sure how you get there if the annoying little clippy is in the way

Find the next-to-last chapter "Programming Information"

Open the "Visual Basic Language Reference" sub-chapter. Open Functions, H-L and find the documentation on the HEX function.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Excel decimal to binary (32 bit) conversion


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT