473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Related to string to binary conversion

I am doing project on Image steganography. First i read the string. Then, I convert it to binary using below code.
for(std::size_t i=0;i<str.size();i++)
{
cout<<(bitset<8>(str[i]));
}
the ouput is binary format. But i need to save the binary format of complete string(not each character) to access each bit of the string to hide it in image. HOw to concatenate the multiple bitsets. Please help me....
Apr 22 '15 #1
1 1605
weaknessforcats
9,208 Expert Mod 8TB
Use an array of usigned long.

You can use bitset::to_ulong to convert the bitset to an unsigned long integer.

A bitset<8> will have a value 0-255 so the bits will be in the low end of the unsigned int.

You should be able to write a function with a unsigned long& as a argument, bitset<8>&, and an enum with a value of OFFSET0, OFFSET8, OFFSET16,etc..

The function stores the bitset into the unsigned int offset by the value of the enum. It will convert the bitset to an unsigned long using bitset::to_ulong.

Since your unsigned int array is guaranteed to be contiguous in memory, your string can be converted into one contiguous array of bits.

BTW: Instead of using a bitset why bit use str[i] -49 to get the correct bits for the char?
Apr 22 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I'm shipping an application using py2exe. With Python2.3 it worked fine but when switching to Python2.4 I started getting "warning: string/unicode conversion" all over the place. ...
2
by: Raja | last post by:
IS there any inbuilt decimal to binary conversion function in C++
16
by: Mars | last post by:
I'm writing a program for listing all binary numbers of the same length with the same number of 1s. e.g. 0011 0101 0110 1001 1010 1100
4
by: godavemon | last post by:
I'm using python's struct and binascii modules to write some values from my parser to binary floats. This works great for all of my binary files except one. For some reason this file is saving to...
12
by: bimbam | last post by:
Hi, I wish to compare 2 black and white images of about 4000 pixels. So I have 2 arrays of 4000 integers int of value 0 or 1. My idea was to convert each array to a single binary number built by...
14
realin
by: realin | last post by:
hi guys i am trying to make a program to convert decimal number into binary .. i am able to do that, but the number comes inverted.. like 1101 comes like 1011 now how do i swap it off.. ...
1
by: farahomer | last post by:
Hi !! I have a question. I am developing a code in C#.NET. So here I have a long string in this format: 000000000010 000000100100 (for example). Its 24 digit long, split into 12 digits by a space in...
7
by: azrael | last post by:
Hy folks, I googled, and searched, and can not bealive that I have not found a built in way to convert the easy and elegant python way a function to easily convert simple ascii data to binary...
4
by: dondigitech | last post by:
I want to convert hex to binary without losing bits. I want to preserve the 8-bits because I ultimately need a 24-bit string to grab information from. I am just using this line of code for the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.