First off my programming experience is very limited and I haven't used C/C++ in the past 4/5 years so I'm fairly c**p at it.
Basically I'm trying to write a function that opens a .wav file and store the binary version of this file in a variable named 'input'. 'input' is a [num]x[16] integer array. 'num' is the no. of bits in the array divided by 16 (rounded up). The following is my code: -
using namespace std;
-
-
FILE *fp;
-
-
int main(int argc, char *argv[])
-
{
-
int *inp, num, i=0, j=0, k=0;
-
long size;
-
if((fp=fopen("out.wav","rb"))==NULL) {
-
printf("cannot open file\n");
-
exit(1);
-
}
-
-
-
fseek (fp, 0, SEEK_END);
-
size= ftell(fp);
-
printf("size of my file is %ld bits\n",size);
-
fseek (fp, SEEK_CUR, SEEK_SET);
-
-
inp = (int *) calloc(size, sizeof(int));
-
-
fread(inp,size,1,fp);
-
fclose(fp);
-
//printf("%f", inp);
-
/*
-
for(int i=0; i<size; i++)
-
{
-
printf("%d", inp[i]);
-
}
-
*/
-
printf("\n");
-
-
num = size/16;
-
-
-
if(size%num!=0)
-
num++;
-
printf("The size of this file can be represented by %d hexadecimal numbers \n", num);
-
int input[num][16];
-
-
k=0;
-
-
for(i=0; i<num; i++)
-
{
-
for(j=0; j<16; j++)
-
{
-
(input)[i][j] = (*inp+k);//[k];
-
k++;
-
}
-
-
}
-
printf("\nThe following is the third input:\n");
-
for(int jj=0; jj<16; jj++)
-
{
-
-
if (jj%4!=0)
-
{
-
//printf(" %d",input[3][jj]);
-
printf(" %d",input[3][jj]);
-
}
-
else
-
{
-
//printf(" %d",input[3][jj]);
-
printf(" %d",input[3][jj]);
-
}
-
}
-
printf("\n\n");
-
-
-
-
//run encryption code for all arrays!
-
-
system("PAUSE");
-
return EXIT_SUCCESS;
-
}
-
When I compile the above code and I printf one of the rows of the variable input the screen prints out 16 10-digit numbers(presuma bly that's the address). I'm expecting input to be a matrix with rows of size 16 containing 1's and 0's. If anyone can suggest where I might be going wrong it would be much appreciated.
1 5692 DeMan 1,806
Top Contributor
Consider
The line: -
(input)[i][j] = (*inp+k);//[k];
-
store at input[i][j] the Value at inp with k added.
Firstly, you would want *(inp+k) // the value k positions beyond inp.
Secondly input is an array of integers, so the value at this location is 32 bits (not 1). Furthermore, the compiler tries to be clever and (inp+k) is actually k int-lengths beyond inp, not k bits.
Using the same sort of array you already have, you could create a function that creates binary values by :
input[a][0] == (value >> 16) &1;
input[a][1] == (value >> 15) & 1;
input[a][2] == (value >> 14) & 1;
(ie right shift x bits (and use logical and to only worry about the last bit);
Or there is probably a way to output binary (You might like to see if this link helps you at all.
Good luck!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Laurent Therond |
last post by:
Maybe you have a minute to clarify the following matter...
Consider:
---
from cStringIO import StringIO
def bencode_rec(x, b):
t = type(x)
|
by: nickisme |
last post by:
Hi - sorry for the possibly stupid question, but I'm still a wee
starter on c++... Just wondering if there's a quick way to convert data
into binary strings...
To explain, I'm trying to convert numbers into 16 bit binary form, so
that I can eventually alter the LSB for dithering purposes. Obviously I
can create my own function that will do this, but I was wondering if
there was some quick process that I could call up from a library that...
|
by: Pete |
last post by:
Sorry for the ambiguity of my last post, What I am try to do is enter a 10
bit binary string
eg: 1110001010 and then permute them into an array using an array containing
3,5,2,7,4,10,1,9,8,6 as the index, so the 1st bit will be in the P10_out,
2nd bit in P10_out and so on. I am sure the problem is to do with the
input string, it is each 1 and 0 of the input is not being read as
individual elements. Your help is much appreciated.
...
|
by: ruben.de.visscher |
last post by:
I am trying to write a program that encrypts 8-bit plaintext using a
10-bit key. To generate subkeys, and for other things, i will need to
be able to perform permutations on binary strings for example:
if k1k2k3k4k5k6k7k8k9k10 represents all ten digits of the key, the
outpur of the permutation should be like this:
k3k5k2k7k4k10k1k9k8k6 .
I am new to operations on binary strings and i don't really know how to
implement this as...
|
by: Patrik Malmström |
last post by:
How do I read, write a file binary?
I want to open, say, file.exe read it in to the program, then write it out
to file2.exe.
Like file copy, anyone have a code sample?
| |
by: ruffiano |
last post by:
Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?
Thanks in advance.
|
by: CharlesL |
last post by:
I am trying to handle binary strings in php. I get a binary output
initialization vector from mcrypt as such:
from mcrypt:
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
This output may have padded nulls at the end which are significant.
I would like to convert all characters including all padding nulls at
end and convert it in a string to be saved into a database in such a way
|
by: nguser3552 |
last post by:
Hello everyone,
I'm wondering if someone out there knows how in a visual c++ console
application how I can do the following, and man I've tried, it seems simple
really:
I need to open up any file (the fnctl library offers hope), in binary or raw
mode just 1' and 0's whichever is preferable. Once the file is open,
attached to a stream and a buffer is created, I have to be able to take the
final object as though
|
by: Terry Reedy |
last post by:
A. Joseph wrote:
These are number representation systems that can be applied to or used
with integral, rational (numberator,denominator), and 'point' numbers.
Try Wikipedia or any search engine.
There are standard algorithms for converting between representations.
See above. Good programmer calculators have these built in.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |