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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:44:14+00:00 2026-06-12T05:44:14+00:00

im trying to implement bit shifting to bigints. The BigInt is represented by an

  • 0

im trying to implement bit shifting to bigints. The BigInt is represented by an array of bytes that should be interpreted as a single integer N bits in two’s complement. So i want to make something like:

Example array bigint:
{0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} would represent the integer 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE (-2) N = 128 bits.

typedef unsigned char *BigInt;

when i try to create my bigint im getting errors

#include <stdlib.h>

    void bi_init (int nbits)
    {
        nbytes = (nbits/8);
    }

    BigInt bi_new (int val)
    {
        BigInt new = (BigInt)malloc(nbytes*sizeof(unsigned char));

        new=val --> problem, can someone give me a hint on how can i implement this array?

        return novo;
    }
  • 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-12T05:44:16+00:00Added an answer on June 12, 2026 at 5:44 am
    typedef unsigned char *BigInt;
    
    BigInt *new = (BigInt)malloc(nbytes*sizeof(unsigned char));
    

    You declare new as an unsigned char**, that’s one level of pointers too many (and you shouldn’t cast the result of malloc in C).

    Assuming that novo and new are the same variable and only one occurrence has been translated for the post,

    novo=val

    overwrites the just allocated address with the passed-in val.

    To fill the allocated buffer with the bytes of val,

    int i = 0;
    // make it unsigned, so that right-shifting works correctly
    unsigned int u_val = val;
    while(u_val) {
        new[i++] = u_val&0xFF;
        u_val >>= 8;
    }
    

    Then there remains the problem

    nbytes = (nbits/8);
    

    that you’re allocating too little memory if nbits is not a multiple of 8, make that

    nbytes = (nbits+7)/8;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a bit of functionality that will behave much like the
I am a bit stuck trying to implement a method that dynamically initializes a
I am trying to implement this bit of code: func factorial(x int) (result int)
Im trying to implement a GA with tournament selection, but im a bit confused.
I am trying to implement this demo on my local machine. http://bit.ly/4g4o1r I have
I'm trying to re-implement an old Reversi board game I wrote with a bit
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
I am trying to implement recursive deletion of Registry Keys for both 32-bit and
I'm trying to implement an image zoom effect, a bit like how the zoom
I am trying to implement a moving photo slider that is no jQuery ,

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.