Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:47:47+00:00 2026-06-09T20:47:47+00:00

How does one convert a string of colon-separated hexadecimal numbers into a ctypes array

  • 0

How does one convert a string of colon-separated hexadecimal numbers into a ctypes array of c_ubyte? According to the ctypes docs, I can cast a hard-coded collection, like so:

>>> from ctypes import *
>>> x = (c_ubyte * 6) (1, 2, 3, 4, 5, 6)
>>> x
<__main__.c_ubyte_Array_6 object at 0x480c5348>

Or, like so:

>>> XObj = c_ubyte * 6
>>> x = XObj(1, 2, 3, 4, 5, 6)
>>> x
<__main__.c_ubyte_Array_6 object at 0x480c53a0>

However, I cannot figure how to cast a variable list, like one generated from splitting a string, for example:

>>> mac = 'aa:bb:cc:dd:ee:ff'
>>> j = tuple(int(z,16) for z in mac.split(':'))
>>> j
(170, 187, 204, 221, 238, 255)
>>> x = (c_ubyte * 6) (j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required
>>> XObj = c_ubyte * 6
>>> x = XObj(j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

What am I missing?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:47:48+00:00Added an answer on June 9, 2026 at 8:47 pm

    The problem is that in the first example you provided, you’ve used ctypes correctly by giving 6 arguments to XObj call, and in the second example (with mac address), you try to call the same object c_ubyte * 6, giving it a tuple, but not 6 values, so convert it using *args notation:

    from c_types import c_ubyte
    
    mac = 'aa:bb:cc:dd:ee:ff'
    j = tuple(int(z,16) for z in mac.split(':'))
    
    converted = (c_ubyte * 6)(*j)  # *j here is the most signigicant part
    print converted
    

    And the result is:

    <__main__.c_ubyte_Array_6 object at 0x018BD300>
    

    as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does any one know how to convert string into date according to user's culture
Given this string: Fri, 09 Apr 2010 14:10:50 +0000 how does one convert it
How does one write a (Intel) F90 function that converts a string into lowercase
Does Cocoa provide a built-in method to convert a key string into a properly-formatted
How does one convert an empty string to an int using Struts2. When the
How can I convert a string of bytes into an int in python? Say
How does one convert a string of a date without a year to a
how does one convert from a list of characters to a string? To put
I need to convert a string of numbers into a string of letters to
How does one convert from an int or a decimal to a float in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.