Results 1 to 2 of 2

Thread: Help with Converting Qword To Byte...

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    40

    Question Help with Converting Qword To Byte...

    This question is also posted in the vb.net forum(I did not know there was a math forum at the time of posting)

    I am new to VB.Net (about 3weeks into learning) and I decided to create a Scientific Calculator as a learning project(similar to the calc in windows). I have the program performing basic function such as: Addition, Subtraction etc. I now am trying to complete the base convergence(from base10 -base2 etc.). Right now I can convert a number to and from either base but my problem is converting the word size(Qword - Dword - Word - Byte). As in the windows calc, If you typed a binary number with "Qword" set and then selected "Byte" it will convert the (64bit) number to a (8bit) number. My question is, does any one know how this is done? Even if someone could just explain it mathmatically I can apply it to what I have learned so far. Here is an example:
    In windows calc

    enter base10: 2500
    switch to binary(Qword Set): 100111000100
    Still in Binary, switch (Qword to Byte): 11000100

    Now I get the proper binary number (from base10 - base2) but going from Qword to Byte is the problem.

    The code I have for converting base10 to base2 is:

    Public Function DTB(ByVal Dec As String) As String
    Dim ct As Integer
    Dim tn, rtn As String
    Dim n As Long
    ct = Dec.IndexOf(".")
    If ct > 0 Then
    tn = Dec.Substring(0, ct)
    n = tn
    Else
    n = Dec
    End If
    rtn = Trim(Str(n Mod 2))
    n = n \ 2
    Do While n <> 0
    rtn = Trim(Str(n Mod 2)) & rtn
    n = n \ 2
    Loop
    keyData = rtn
    End Function

    If someone can help me with this I would greatly appreciate it!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Re: Help with Converting Qword To Byte...

    it looks like BYTE = QWORD and &HFF
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width