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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:30+00:00 2026-05-28T06:48:30+00:00

Not sure how else to put that, but I’ll start off with a code

  • 0

Not sure how else to put that, but I’ll start off with a code snippet and output:

uint32_t expires;

cout << "Expiration bytes: " << setfill('0') << hex
     << setw(2) << (unsigned short)rec[keyLen+4]
     << setw(2) << (unsigned short)rec[keyLen+5]
     << setw(2) << (unsigned short)rec[keyLen+6]
     << setw(2) << (unsigned short)rec[keyLen+7] << endl;

expires = ntohl(*(uint32_t*)&rec[keyLen+4]);

cout << "Expiration: " << (long)expires << endl;

cout << "Hex: " << hex << expires << endl;

Outputs:

Expiration bytes: 00000258
Expiration: 258
Hex: 258

I can confirm from other parts of the program that examining and outputting the hex representation of bytes works as expected, and that those are indeed the bytes in the byte stream (sent from another application).

Now, I would be able to understand a bit better if expiration just held some nonsense, because that would mean there’s some egregious error (probably involving pointers). But this… this is clearly just spitting out the hex value as if it were a decimal, and that’s plain wrong.

To make matters more confusing, this works at another point in the program:

fullSize = ntohs(*(uint16_t*)&buff[0]);

With a byte value of 0x0114, fullSize will contain the value 276.

So the question is, what the heck is going on here? How is it possible for an int to be wrong?

  • 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-28T06:48:30+00:00Added an answer on May 28, 2026 at 6:48 am

    cout << "Expiration: " << dec << (long)expires << endl; will output decimal, otherwise the last setting (hex or dec) will still be in effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That title is brutal, but I don't know how else to put it. I
I'm trying to put some C hooks into some code that someone else wrote
I'm not sure if I need a lambda, or something else. But still, I
I'm not sure how else to describe this, outside of calling it a newspaper
Not sure how to ask a followup on SO, but this is in reference
Not sure what exactly is going on here, but seems like in .NET 1.1
Not sure if the title is quite right for the question but I can't
Not sure if anyone listened to Hanselminutes episodes 134 and 135, but at the
Not sure this is a programming question, but we use LaTeX for all our
Okay, so not sure if apple.stackexchange is a better place for this, but I

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.