Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rotate bits ?
#1
Hello,
I have a function that take bits and cut them according to my needs
BITS_ORDER_CHANGE = {8: 0, 7: 1, 6: 2, 5: 3, 4: 4, 3: 5, 2: 6, 1: 7}

def GetBits(Byte, start, end):  # bits order 8765 4321 , str order 0123 4567
    Final_calculation = round((int(Byte, 16) * 1 + 0), 0)
    bits = "{0:b}".format(Final_calculation)
    Full_bits = bits.zfill(8)
    print('old start', start)
    start = BITS_ORDER_CHANGE[start]
    print('new start', start)
    print('old end', end)
    end = BITS_ORDER_CHANGE[end]
    print('new end', end)
    Wanted_bits = Full_bits[end:start]
    return Wanted_bits
my problem is that when I cut it I think is string mode , whie the bits are is in bits mode
so it's other way around

for example
if I take "CA"
in bits its - 1100 1010
I want to cut only bits 2-4
but I need to enter numbers 4-7

then I thought to use dictionary - but then it's went wrong
I need to change the order - (end - start) , and it also change the order of the bits
01 - change to 10

is there other way to do it? without overthinking what need to be cut?


Thanks,
Reply


Messages In This Thread
How to rotate bits ? - by korenron - Mar-23-2022, 01:51 PM
RE: How to rotate bits ? - by deanhystad - Mar-23-2022, 02:52 PM
RE: How to rotate bits ? - by Larz60+ - Mar-23-2022, 04:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,119 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  From list of bits to PDF drimades 1 1,952 Nov-02-2021, 08:55 PM
Last Post: Gribouillis
Exclamation Help in breaking bytes into bits through masking and shifting kamui123 9 4,642 Jan-11-2021, 07:42 AM
Last Post: kamui123
  Rotate 2D Gaussian given parameters schniefen 4 2,959 Dec-11-2020, 03:34 PM
Last Post: schniefen
  How to rotate log and limit the size maiya 0 1,774 Aug-29-2020, 12:41 AM
Last Post: maiya
  rounding floats to a number of bits Skaperen 2 2,342 Sep-13-2019, 04:37 AM
Last Post: Skaperen
  Problem with Pycharm 64 bits sylas 12 10,337 Jan-22-2018, 02:19 PM
Last Post: sparkz_alot
  send bits to the signal generator liorjo 2 3,137 Dec-20-2017, 07:46 PM
Last Post: liorjo
  How to convert python files from 32 bits tto 64 bits sylas 2 5,121 Oct-29-2017, 03:51 AM
Last Post: Larz60+
  Why are two similar bits of code giving different results? godmode 10 10,062 Dec-15-2016, 09:53 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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