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 379991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:56:44+00:00 2026-05-12T14:56:44+00:00

I have a varchar column in Postgres 8.3 that holds values like: ‘0100011101111000’ I

  • 0

I have a varchar column in Postgres 8.3 that holds values like: ‘0100011101111000’

I need a function that would consider that string to be a number in base 2 and spits out the numeric in base 10. Makes sense?

So, for instance:

‘000001’ -> 1.0

‘000010’ -> 2.0

‘000011’ -> 3.0

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-05-12T14:56:44+00:00Added an answer on May 12, 2026 at 2:56 pm

    Cast to a bit string then to an integer.

    An example:
    '1110'::bit(4)::integer -> 14

    Though you had varying length examples, and were after bigint, so instead use bit(64) and pad the input with zeroes using the lpad function.

    lpad('0100011101111000',64,'0')::bit(64)::bigint

    Here’s a complete example…

    create temp table examples (val varchar(64));
    
    insert into examples values('0100011101111000');
    insert into examples values('000001');
    insert into examples values('000010');
    insert into examples values('000011');
    
    select val,lpad(val,64,'0')::bit(64)::bigint as result from examples;
    

    The result of the select is:

           val        | result 
    ------------------+--------
     0100011101111000 |  18296
     000001           |      1
     000010           |      2
     000011           |      3
    (4 rows)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have column with varchar values like 022008 that I need to convert into
I have a VARCHAR column that contains comma separated values and I would like
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I have a SQL varchar column that has values like 100, 2000 and S5000.
I have a varchar column that has data like this top<somenumber> so the word
I have a Varchar day column and I would like to select all rows
I have a database with VARCHAR column url . I would like to fetch
I have a datetime column that I need to alter to be a varchar
I have a table with a varchar column with values that should be integers
I have a varchar(100) column in a table that contains a mix of integers

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.