Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,080 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,797 people online right now. Registration is fast and FREE... Join Now!




help about structure

 
Reply to this topicStart new topic

help about structure

allopiloping
1 Jun, 2008 - 09:45 PM
Post #1

New D.I.C Head
*

Joined: 4 Apr, 2008
Posts: 4

CODE

Private Structure word
        Dim b1 As Byte
        Dim b2 As Byte
        Dim b3 As Byte
        Dim b4 As Byte
    End Structure

Private Function DoubleToWord(ByVal n As Double) As word
        DoubleToWord.b1 = Int(DMod(n, 2 ^ 32) / (2 ^ 24))
        DoubleToWord.b2 = Int(DMod(n, 2 ^ 24) / (2 ^ 16))
        DoubleToWord.b3 = Int(DMod(n, 2 ^ 16) / (2 ^ 8))
        DoubleToWord.b4 = Int(DMod(n, 2 ^ 8))
    End Function

Private Function WordToDouble(ByVal w As word) As Double
        WordToDouble = (w.b1 * (2 ^ 24)) + (w.b2 * (2 ^ 16)) + (w.b3 * (2 ^ 8)) + w.b4
    End Function

Private Function HexToWord(ByVal H As String) As word
        HexToWord = DoubleToWord(Val("&H" & H & "#"))
    End Function

Private Function WordToHex(ByVal w As word) As String
        WordToHex = Hex(w.b1).PadLeft(2, "0") & Hex(w.b2).PadLeft(2, "0") & Hex(w.b3).PadLeft(2, "0") & Hex(w.b4).PadLeft(2, "0")
    End Function


i have a few function...this function is to convert from word to hex

i don't knw how to make the convert from word to binary......plz help me

what should i do...????
thx
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Help About Structure
2 Jun, 2008 - 03:47 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,282



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
It's in binary. tongue.gif

If you're looking for some kind of string representation of the binary, you could try something like this:

CODE

Function BitsForByte(ByVal n As Byte) As String
    Dim i As Integer, bits As String = ""
    For i = 7 To 0 Step -1
        bits += IIf((n And 2 ^ i) > 0, "1", "0")
    Next
    Return bits
End Function


Hope this helps.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:27PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month