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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:29:16+00:00 2026-06-18T03:29:16+00:00

I have a void pointer that I would like to store the binary value

  • 0

I have a void pointer that I would like to store the binary value of a long at. For example:

void * p;
long number;

p = malloc(16);
p = memset(p, 0, 16);
number = 15;

/* PRINTS FIRST 16 BYTES */
for(i = 0; i < memSize; i++)
     printf("%02x", ((unsigned char *) p) [i]);
printf("\n");

Above code will print

00000000000000000000000000000000

I would like to set the first 8 bytes to the value of “number”, for example:

000000000000000F0000000000000000

Is there a simple way of doing this? I suppose bit shifting would work, but that could become quite tedious.

  • 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-18T03:29:18+00:00Added an answer on June 18, 2026 at 3:29 am

    Why not use memcpy?

     memcpy (p, &number, sizeof(number));
    

    Do you care about the order of bytes (most significant vs least significant first)? Perhaps you should read http://en.wikipedia.org/wiki/Endianness

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

Sidebar

Related Questions

I have a pointer value stored at b+4 that I would like to load
I have a smart pointer type, and would like to construct an object that
I have a function that returns a pointer: static void *find_fit(size_t asize); I would
Lets say you have various objects of arbitrary type that you would like to
I have a problem that I would like to tell you because is about
I would like to store a pointer to the main Game class in my
I have a structure that has an array of pointers. I would like to
I have a void pointer returned by dlsym(), I want to call the function
I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function generic, so it
I am sorry for the long text but I would like to present the

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.