Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# From Integer to Bytes

Posted on 2002-06-16
Medium Priority
217 Views
How can I get the 2 bytes values from an Interger?
0
Question by:DImirC
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 44

Accepted Solution

bruintje earned 400 total points
ID: 7082244
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

Author Comment

ID: 7082527
Thanks,

Do you know how to make the invers process also?  from bytes to Integer?
0

Expert Comment

ID: 7082535
byte1 = CInt((CLng(int1) And &HFF00) \ 256)
byte2 = int1 And 255
0

Expert Comment

ID: 7082538
inverse process is

int1 = byte2 + (byte1 * 256)
0

LVL 44

Expert Comment

ID: 7082541
well Hobbithouse was way faster
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month10 days, 12 hours left to enroll