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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:52:43+00:00 2026-06-02T00:52:43+00:00

I am using a big number (over 128 bits integer) in my code. I

  • 0

I am using a big number (over 128 bits integer) in my code. I find that c++ have std::bitset to simple some operation so I don’t have to break my data into several integers. But I soon find another issue, if I have to convert several (long) integers into bitset, what’s the best way to do that? For example, I am trying to convert four long integers (each of 32bits) to a 128bit bitset, the following way doesn’t work because for each integers (the shift operation will only work for shifted bits less than 32)

std::bitset<256> b;
unsigned long v1=2, v2=9, v3=19, v4=1021;
b |= v1 | (v2<<32) | (v3<<64) | (v4<<128);

Now I use a for loop to set each bit on the bitset but I am looking for a more efficient and elegant way to do so.

  • 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-02T00:52:44+00:00Added an answer on June 2, 2026 at 12:52 am

    This might not be the best option, but what about this?

    typedef std::bitset<256> bs256;
    b |= bs256(v1) | (bs256(v2) << 32) | (bs256(v3) << 64) | (bs256(v4) << 128);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using GMP on c, I have a big integer mpz_t n in decimal form,
We have a pretty big perl codebase. Some processes that run for multiple hours
I have a big form that is split over 3 pages (each page is
I cant find why I got a java.lang.ArithmeticException: Invalid operation while using big decimal.
Problem: I am using a big C/C++ code base which works on gcc &
I'm using Apache HttpClient 3.x for contacting a Big IP that will then redirect
I'm a happy user of Github. Over time I have accrued a number of
I have a big number pdf documents with xml files attached to them. I
I have a remote web server that I have full administrator access over, and
I have created a VBA script that detects a number and shows a colour

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.