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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:25:39+00:00 2026-05-11T09:25:39+00:00

Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit

  • 0

Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit literal), I’d like to read it as an array of char, or, better, I’d like to printout the ASCII value of 8 consecutively bits of the memory.

I have allocated he memory as char *, but I’ve not been able to take characters out in a better way than evaluating each bit, adding the value to a char and shifting left the value of the char, in a loop, but I was looking for a faster solution. Thank you

What I’ve wrote for now is this:

for allocation:

char * bits = (char*) malloc(1); 

for writing to mem:

ifstream cleartext; cleartext.open(sometext); while(cleartext.good()) {      c = cleartext.get();      for(int j = 0; j < 8; j++)      {  //set(index) and reset(index) set or reset the bit at bits[i]         (c & 0x80) ? (set(index)):(reset(index));//(*ptr++ = '1'):(*ptr++='0');          c = c << 1;      }.. }.. 

and until now I’ve not been able to get character back, I only get the bits printed out using:

printf('%s\n' bits); 

An example of what I’m trying to do is:

input.txt contains the string ‘AAAB’

My program would have to write ‘AAAB’ as ‘01000001010000010100000101000010’ to memory (it’s the ASCII values in bit of AAAB that are 65656566 in bits)

Then I would like that it have a function to rewrite the content of the memory to a file.

So if memory contains again ‘01000001010000010100000101000010’ it would write to the output file ‘AAAB’.

  • 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. 2026-05-11T09:25:40+00:00Added an answer on May 11, 2026 at 9:25 am
    int numBytes = 512; char *pChar = (char *)malloc(numBytes); for( int i = 0; i < numBytes; i++ ){    pChar[i] = '8'; } 

    Since this is C++, you can also use ‘new’:

    int numBytes = 512; char *pChar = new char[numBytes]; for( int i = 0; i < numBytes; i++ ){    pChar[i] = '8'; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a item list that shows on my asp.net page like this:
Hello I have this list that i am working on. When i move the
Hello I have a Dynamic DataTable Created at runtime. The Setup is like so
Hello I have a form like below: <form method=post action=> <fieldset><legend>Products List</legend> <ul> <li><input
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have a problem with c# Arrays. I need a array to store
Hello I have the Addin for Word 2007 that is creted using VSTO. I
Hello I have a view that deletes order numbers. Once a string has been
Hello I have a problem with a binding that I want to do and
I used to think that each memory location contains 8, 16, 32 or 64

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.