• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

From Integer to Bytes

How can I get the 2 bytes values from an Interger?
0
DImirC
Asked:
DImirC
  • 2
  • 2
1 Solution
 
bruintjeCommented:
Hi DImirC,

maybe this snippet from Harvey Triana will help

By example (buil in memory an Integer):

'//Integer bytes
Private Type udtIntBytes
    B1 As Byte
    B2 As Byte
End Type

'//Integer
Private Type udtInt
    n As Integer
End Type

Private Sub Test()
    Dim MyInt As udtInt
    Dim b     As udtIntBytes

    MyInt.n = 2001

    LSet b = MyInt
End Sub

b contain the two bytes of Integer.


HAGD:O)Bruintje
0
 
DImirCAuthor Commented:
Thanks,

Do you know how to make the invers process also?  from bytes to Integer?
0
 
HobbitHouseCommented:
   byte1 = CInt((CLng(int1) And &HFF00) \ 256)
    byte2 = int1 And 255
0
 
HobbitHouseCommented:
inverse process is

int1 = byte2 + (byte1 * 256)
0
 
bruintjeCommented:
well Hobbithouse was way faster
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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