Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

High Byte

Posted on 1997-12-03
5
Medium Priority
?
526 Views
Last Modified: 2008-02-20
I need to split and integer in to bytes.

I have suceded getting the low byte doing a bitwise AND with 255.

How can i get the high byte of an integer??
0
Comment
Question by:PedroMVGomes
[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
  • Learn & ask questions
  • 4
5 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 150 total points
ID: 1443381
Function HiByte(Pass As Integer) As Byte

   If (Pass And -2 ^ 15) = 0 Then
      HiByte = Int(Pass / 255)
   Else
      HiByte = ((Pass And 32512) \ 256) Or 128
   End If

End Function

0
 
LVL 8

Expert Comment

by:mrmick
ID: 1443382
Simplified a bit...

Function HiByte(i As Integer) As Byte

   If i And -2 ^ 15 Then
      HiByte = ((i And 32512) \ 256) Or 128
   Else
      HiByte = i \ 255
   End If

End Function

0
 
LVL 8

Expert Comment

by:mrmick
ID: 1443383
or how about this...

Function HiByte(i As Integer) As Byte
Dim Sign As Boolean

   Sign = i And -2 ^ 15
   HiByte = ((i And 32512) \ 256) Or (128 And Sign)

End Function

Note: All three work!

0
 
LVL 6

Expert Comment

by:alamo
ID: 1443384
yes, yet another way, and without stripping the sign bit first

In case you'd like to see it in decimal:

Function HiByte(i As Integer) As Byte

   HiByte = (i And 65280) / 256 And 255

End Function



0
 
LVL 8

Expert Comment

by:mrmick
ID: 1443385
How can i do the reverse, this is i have to bytes the low one and the higher one how can a calculate the integer??
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question