Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

How to access individual bytes in Single

I have a single that I want to access each individual byte of. How can I do this?

dim stuff as single


var1 = stuff.byte0
var2 = stuff.byte1
var3 = stuff.byte2
var4 = stuff.byte3

Thanks
0
DavidBonfoey
Asked:
DavidBonfoey
1 Solution
 
TigerZhaoCommented:
Declare Sub CopyMemoryLpToLp Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As Long, ByVal pSrc As Long, ByVal ByteLen As Long)

Sub Main()
    Dim stuff As Single
    Dim ba(0 To 3) As Byte

    stuff = 1234.5678
   
    CopyMemoryLpToLp VarPtr(ba(0)), VarPtr(stuff), 4&
   
    Debug.Print ba(0)
    Debug.Print ba(1)
    Debug.Print ba(2)
    Debug.Print ba(3)
End Sub
0
 
spauljosephCommented:
Use this.

Dim sngVar as Single
Dim bytVar() as Byte


bytVar = StrConv(CStr(sngVar),vbFromUnicode)

Debug.Print bytVar(0)
....

0
 
DavidBonfoeyAuthor Commented:
Thanks!

Works great!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now