Python Forum
Four sequential bytes; Need to remove high order bit in each to get correct output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Four sequential bytes; Need to remove high order bit in each to get correct output
#3
(Jan-20-2021, 05:00 AM)bowlofred Wrote: So sounds like you want to treat the 4 bytes as a single 28-bit number. In that case I would:

* initialize total to zero
* starting with the high-order byte, loop over the four bytes
** shift the total left by 7 bits (total << 7)
** add the current byte & 127 to the total.

Okay, I get the concept but am having a problems translating it to code.
Just to make sure we are on the same page, I read 4 consecutive bytes (total of 32 bits) from
a file and I need to make a 28 bit number by removing the most significant bit from each byte.
Reply


Messages In This Thread
RE: Four sequential bytes; Need to remove high order bit in each to get correct output - by GrandSean - Feb-06-2021, 03:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sequential number for rows retrieved and storing the Primary UKey to the line number GYKR 2 620 Aug-22-2023, 10:14 AM
Last Post: GYKR
  Create a sequential number (counter) and reset at each duplicate Mekala 0 1,761 Sep-20-2020, 05:02 AM
Last Post: Mekala
  attribute error instead of correct output MaartenRo 2 2,224 Aug-28-2020, 10:22 AM
Last Post: Larz60+
  Visual Studio-remove Output clutter mds 14 8,950 Jun-04-2020, 11:47 PM
Last Post: mds
  Finding sequential invoice william888 0 1,386 Mar-24-2020, 12:41 AM
Last Post: william888
  Sequential color background swisha 2 2,049 Mar-05-2020, 03:43 PM
Last Post: Larz60+
  GPIO time in HIGH LOW boris_za 1 2,313 Dec-07-2019, 01:48 PM
Last Post: Larz60+
  Not getting correct output supriya0307 5 5,603 Sep-10-2019, 10:28 PM
Last Post: ichabod801
  Not quite getting the correct Output from a function twinpiques 3 2,708 Aug-04-2019, 11:53 PM
Last Post: twinpiques
  understanding output of bytes/raw data rootVIII 3 2,805 Aug-01-2019, 01:00 PM
Last Post: rootVIII

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020