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

  • SEARCH
  • Home
  • 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 8700973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:25+00:00 2026-06-13T02:17:25+00:00

My question is related to this stackoverflow post: enter link description here , in

  • 0

My question is related to this stackoverflow post: enter link description here, in which inspectorG4dget provided the code

def decToBin(n):
    if n==0: return ''
    else:
        return decToBin(n/2) + str(n%2)

which recursion Alex Martelli observed was unnecessary, since the obvious bin(x)[2:] could be used. This is fine if the user needs the binary representation as a string. However, I need the binary representation as a list or numpy ndarray. As I can see, my options are a) adaptation of this code or b) something like this string.split(','.join(bin(10)[2:]),','). I know string operations tend to be expensive, but recursion can also be expensive.

Given that I need to convert an integer into an array_like of bits, which option (a or b) is likely to be more efficient? Is there another simpler & better way completely?

  • 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-13T02:17:26+00:00Added an answer on June 13, 2026 at 2:17 am

    You can simply convert a string to list by list().

    list(bin(10)[2:])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is related to this link stackoverflow ques In essence repeating the figure
This question is related to a previous post of mine Here . Basically, I
I read all topics related to this question in stackoverflow and whole internet and
This question is related to this SO post Rather than using a recursive CTE
Found this related post, https://stackoverflow.com/questions/7139/should-a-first-release-be-an-0-1-version-or-1-0b , but it is not about Ruby Gems. I
I asked a related question here: Clojure: How do I turn clojure code into
This question is related to this one: https://stackoverflow.com/questions/7906356/how-to-solve-a-a-reference-tracked-object-changed-reference-during-deserializat Since the above post has been
This is a follow up on a related topic found here https://stackoverflow.com/questions/1987485/conditionally-assign-c-var-as-elegant-as-it-get s if
This question is related to the post about having abstract at the titlepage. I
I've used stackoverflow many a time to solve my problems (code related!) but this

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.