Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a binary data into c_ubyte_Array_64 in python

How to convert ` b’\x00\x00\x00\x00\x00\x00\x00\x01′ c_ubyte_Array_64 in python. I could find any resources only so any help would really appreciated.

I have to send this message which should be of type c_ubyte_Array_64

import ctypes
messages = {
    "RESET": b'\x00\x00\x00\x00\x00\x00\x00\x01',
}

ba = bytearray(messages['RESET'])

I tried it in the above manner but it gives me this error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TypeError: expected c_ubyte_Array_64 instance, got bytearray

>Solution :

The way to convert:
(ctypes.c_ubyte * 64)(*[ctypes.c_ubyte(x) for x in ba])

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading