Jump to content

Manipulating sc_biguint with raw pointer


tmp_sc

Recommended Posts

Hi, 

I want to set the value of `sc_biguint<128>` with `get_raw` method. 
If the value is just initialized to 0, I cannot do it.
E.g. 
 

  sc_biguint<128> val{0x00};
  
  cout << hex << val << endl;
  auto* ptr = val.get_raw();
  *ptr = 0x2AAABBBB;
  cout << hex << val << endl;

output is 
 

000000000000000000000000000000000
000000000000000000000000000000000

 

but in case it had some arithmetic operations, I can. 
E.g. 
 

  sc_biguint<128> val{0x00};

  val += 0xABCDEF0912345678; <--- difference
  
  cout << hex << val << endl;
  auto* ptr = val.get_raw();
  *ptr = 0x2AAABBBB;
  cout << hex << val << endl;

and the output is 

 

00000000000000000abcdef0912345678
00000000000000000abcdef092aaabbbb <--- value is changed

 

Any idea what is the reason for this feature?

Link to comment
Share on other sites

  • tmp_sc changed the title to Manipulating sc_biguint with raw pointer

In the meantime I figured out:


Setting sc_biguint via get_raw pointer is not visible immediately because sc_uint (base class for sc_biguint) has several members. In this case most important ones are
 

private:

  small_type  sgn;         // Shortened as s.
...
  sc_digit *digit;                       // Shortened as d.

 

if we access through get_raw method

sc_digit* get_raw() const { return digit; }

we will update only digit, but not sgn . In case we want to print out the value of sc_biguint, at some moment we will call 
 

bool
sc_unsigned::iszero() const
{
  if (sgn == SC_ZERO)
    return true;

So without updating the sgn, we will get the value 0 even though digit is changed 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...