Results 1 to 4 of 4

Thread: convert long to 4 bytes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    california
    Posts
    245

    convert long to 4 bytes

    Hello,

    I have a Long (172,898) and need to convert it into four bytes.

    The situation is this...I am creating a bit map and need to set the file length in the header. The length of the bitmap varies but it always has to fit into four bytes.

    Thanks for any help...

    - J

    Here's how I did it in VB6 but now I need it in VB.NET:

    Code:
        '(My4Bytes is a data type defined in the module)
    
        LSet My4Bytes = LengthOfFile_Long
    
        tArray(3) = CByte(My4Bytes.b1)
        tArray(4) = CByte(My4Bytes.b2)
        tArray(5) = CByte(My4Bytes.b3)
        tArray(6) = CByte(My4Bytes.b4)

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    california
    Posts
    245
    More info:

    If the length of the file is : 172,872
    The Bytes would be: 48 a3 02 00

    So if you take the bytes backwards they make the following DWord:2A348

    Which equals exactly 172,872.

    But how to automate this?

    Thanks.

    - J

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    california
    Posts
    245
    I think I figured it out...

    Hex()

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You would probably want to look into the BitConverter class as well.

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