Search Results

Search found 4214 results on 169 pages for 'binary serializer'.

Page 121/169 | < Previous Page | 117 118 119 120 121 122 123 124 125 126 127 128  | Next Page >

  • C++: Simplifying my program to convert numbers to from one base to another.

    - by Spin City
    Hello, I'm taking a beginner C++ course. I received an assignment telling me to write a program that converts an arbitrary number from any base between binary and hex to another base between binary and hex. I was asked to use separate functions to convert to and from base 10. It was to help us get used to using arrays. (We already covered passing by reference previously in class.) I already turned this in, but I'm pretty sure this wasn't how I was meant to do it: #include <iostream> #include <conio.h> #include <cstring> #include <cmath> using std::cout; using std::cin; using std::endl; int to_dec(char value[], int starting_base); char* from_dec(int value, int ending_base); int main() { char value[30]; int starting_base; int ending_base; cout << "This program converts from one base to another, so long as the bases are" << endl << "between 2 and 16." << endl << endl; input_numbers: cout << "Enter the number, then starting base, then ending base:" << endl; cin >> value >> starting_base >> ending_base; if (starting_base < 2 || starting_base > 16 || ending_base < 2 || ending_base > 16) { cout << "Invalid base(s). "; goto input_numbers; } for (int i=0; value[i]; i++) value[i] = toupper(value[i]); cout << "Base " << ending_base << ": " << from_dec(to_dec(value, starting_base), ending_base) << endl << "Press any key to exit."; getch(); return 0; } int to_dec(char value[], int starting_base) { char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; long int return_value = 0; unsigned short int digit = 0; for (short int pos = strlen(value)-1; pos > -1; pos--) { for (int i=0; i<starting_base; i++) { if (hex[i] == value[pos]) { return_value+=i*pow((float)starting_base, digit++); break; } } } return return_value; } char* from_dec(int value, int ending_base) { char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char *return_value = (char *)malloc(30); unsigned short int digit = (int)ceil(log10((double)(value+1))/log10((double)ending_base)); return_value[digit] = 0; for (; value != 0; value/=ending_base) return_value[--digit] = hex[value%ending_base]; return return_value; } I'm pretty sure this is more advanced than it was meant to be. How do you think I was supposed to do it? I'm essentially looking for two kinds of answers: Examples of what a simple solution like the one my teacher probably expected would be. Suggestions on how to improve the code.

    Read the article

  • How can I enable auto-updates in a Qt cross-platform app?

    - by FX
    I love applications that are able to update themselves without any effort from the user (think: Sparkle framework for Mac). Is there any code/library I can leverage to do this in a Qt app, without having to worry about the OS details? At least for Windows/Mac/user-owned-linux-binaries. I could integrate Sparkle on the Mac version, code something for the linux case (only for a standalone, user-owned binary; I won't mess with distros packaging, if my program is ever packaged), and find someone to help me on the Windows side, but that's horribly painful. Surely I'm not the only one who wants to provide this to users?

    Read the article

  • iPhone SDK: Downloading large files from a server into the app bundle.

    - by Jessica
    Hi, I am building an app that plays multiple video files, But I would like to know How do you download a video file (100mb - 300mb) from a server into the application's bundle so it can later be locally referred to in code? The reason I want this type of a set up in my app is that I don't want the app binary to be made unnecessarily large due to including videos some users may not want. Also does this violate any of apple's terms? Also would it be simple to implement a progress view with this kind of set up and if so how? Any help is appreciated.

    Read the article

  • Convert integer to equivalent number of blank spaces.

    - by mike
    I was wondering what the easiest way is to convert an integer to the equivalent number of blank spaces. I need it for the spaces between nodes when printing a binary search tree. I tried this `int position = printNode.getPosition(); String formatter = "%1"+position+"s%2$s\n"; System.out.format(formatter, "", node.element);` But I am getting almost 3 times as many spaces compared to the int value of position. I'm not really sure if I am formatting the string right either. Any suggestions would be great! If it makes it clearer, say position = 6; I want 6 blank spaces printed before my node element.

    Read the article

  • Matlab - Propagate unit vectors on to the edge of shape boundaries

    - by Graham
    Hi I have a set of unit vectors which I want to propagate on to the edge of shape boundary defined by a binary image. The shape boundary is defined by a 1px wide white edge. I also have the coordinates of these points stored in a 2 row by n column matrix. The shape forms a concave boundary with no holes within itself made of around 2500 points. What would be the best method to do this? Are there some sort of ray tracing algorithms that could be used? Or would it be a case of taking the unit vector and multiplying it by a scalar and testing after multiplication if the end point of the vector is outside the shape boundary. When the end point of the unit vector is outside the shape, just find the point of intersection? Thank you very much in advance for any help!

    Read the article

  • How to implement B+ Tree for file systems ?

    - by user312544
    I have a text file which contains some info on extents about all the files in the file system, like below C:\Program Files\abcd.txt 12345 100 23456 200 C:\Program Files\bcde.txt 56789 50 26746 300 ... Now i have another binary which tries to find out about extents for all the files. Now currently i am using linear search to find extent info for the files in the above mentioned text file. This is a time consuming process. Is there a better way of coding this ? Like Implementing any good data structure like BTree. If B+ Tree is used what is the key, branch factor i need to use ?

    Read the article

  • Why can't we have an immutable version of operator[] for map

    - by Yan Cheng CHEOK
    The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i = m[0]; But not the following code : // error C2678: binary '[' : no operator... const std::map<int, int>& m = std::map<int, int>(); int i = m[0]; Most of the time, I prefer to make most of my stuff to become immutable, due to reason : http://www.javapractices.com/topic/TopicAction.do?Id=29 I look at map source code. It has mapped_type& operator[](const key_type& _Keyval) Is there any reason, why std::map unable to provide const mapped_type& operator[](const key_type& _Keyval) const

    Read the article

  • [NSData dataWithContentsOfFile:path] doesn't work

    - by Felics
    Hello, when I have the fallowing code to read a binary file: NSString* file = [NSString stringWithUTF8String:fileName]; NSString* filePath = resource ? [[NSBundle mainBundle] pathForResource:file ofType:nil] : [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent: file]; NSData* fileData = [NSData dataWithContentsOfFile:filePath]; Where "fileName" and resource are load function parameters. "resource" is used to know if the file is located in application bundle or in Documents. Sometimes this code works well and sometimes it doesn't. As far I saw this problem is random. I can run the code 10 times in a row and it works fine and after that it gives me nil data without any modification. Does anybody knows what could be the problem? Could it be related with file extension or file name? Thank you. PS: I use this code on iPhone Simulator and the file exists in application bundle.

    Read the article

  • Pyserial : How to send data to drive SIPO

    - by bino oetomo
    Dear All .. I'm learning to drive a stepper motor with Python. It's hard now to find a PC with paralel port. So My plan is using a USB-Serial .. and a SIPO (serial in parallel out) shift register circuit. As you know with this circuit we need to send a binary data in series and this data will be stored in it's register. Next we need to send another one pulse to make it shift the data out to the out-port. How to do it using pyserial ? Sincerely -bino-

    Read the article

  • C++ Boost bind value type

    - by aaa
    hello. I look in documentation and source code but cannot figure out how to get return value type of boost bind functor. I am trying to accomplish following: 35 template<typename T,size_t N, class F> 36 boost::array<typename F::value_type, N> make_array(T (&input)[N], F unary) { 37 boost::array<typename F::value_type, N> array; 38 std::transform(input, input + N, array.begin(), unary); 39 return array; 40 } where F can be bind functor. the above does not work because functor does not have value_type. for that matter, is there standard interface for unary/binary functor as far as return value. Thanks

    Read the article

  • CRC32 calculations for png chunk doesn't match the real one

    - by user2507197
    I'm attempting to mimic the function used for creating CRC's in PNG files, I'm using the autodin II polynomial and the source code from: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/libkern/crc32.c My tests have all been for the IHDR chunk, so my parameters have been: crc - 0xffffffff and 0 (both have been suggested) buff - the address of the IHDR Chunk's type. length - the IHDR Chunk's length + 4 (the length of the chunk's data + the length of the type) I printed the calculated CRC in binary, which I compared to the actual CRC of the chunk. I can see no similarities (little-big endian, reversed bits, XOR'd, etc). This is the data for the IHDR chunk (hexadecimal format): length(big endian): d0 00 00 00 (13) type: 49 48 44 52 data: 00 00 01 77 00 00 01 68 08 06 00 00 00 existing CRC: b0 bb 40 ac If anyone can tell me why my calculations are off, or give me a CRC32 function that will work I would greatly appreciate it. Thank-you!

    Read the article

  • Why does Perl lose foreign characters on Windows input - can this be fixed (if so, how) or is Perl an outdated dinosaur that just can't handle this?

    - by Alex R
    Note below how ã changes to a This is causing me a huge problem as foreign characters show up in URLs, e.g. http://pt.wikipedia.org/wiki/Cão The OS is Windows 7, 64-bit. The Perl is: This is perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-x64-multi-thread (with 8 registered patches, see perl -V for more detail) Copyright 1987-2010, Larry Wall Binary build 1202 [293621] provided by ActiveState http://www.ActiveState.com Built Sep 6 2010 22:53:42 Additional update: To get around my particular problem, I tried using File::Find instead of piped input. The issue actually gets worse:

    Read the article

  • What's the best way to write to more files than the kernel allows open at a time?

    - by Elpezmuerto
    I have a very large binary file and I need to create separate files based on the id within the input file. There are 146 output files and I am using cstdlib and fopen and fwrite. FOPEN_MAX is 20, so I can't keep all 146 output files open at the same time. I also want to minimize the number of times I open and close an output file. How can I write to the output files effectively? I also must use the cstdlib library due to legacy code.

    Read the article

  • c++ normalizing data sizes across systems

    - by Bocochoco
    I have a struct with three variables: two unsigned ints and an unsigned char. From my understanding, a c++ char is always 1 byte regardless of what operating system it is on. The same can't be said for other datatypes. I am looking for a way to normalize POD's so that when saved into a binary file, the resulting file is readable on any operating system that the code is compiled for. I changed my struct to use a 1-byte alignment by adding #pragma as follows: #pragma pack(push, 1) struct test { int a; } #pragma pack(pop) but that doesn't necessarily mean that int a is exactly 4 bytes on every os, I don't think? Is there a way to ensure that a file saved from my code will always be readable?

    Read the article

  • Address of instruction causing SIGSEGV in external program

    - by karramba
    I want to get address of instruction that causes external program to SIGSEGV. I tried using ptrace for this, but I'm getting EIP from kernel space (probably default signal handler?). How GDB is able to get the correct EIP? Is there a way to make GDB provide this information using some API? edit: I don't have sources of the program, only binary executable. I need automation, so I can't simply use "run", "info registers" in GDB. I want to implement "info registers" in my own mini-debugger :)

    Read the article

  • question about missing element in array

    - by davit-datuashvili
    i have following problem from book introduction algorithm second edition by MIT university problem is following An array A[1 . . n] contains all the integers from 0 to n except one. It would be easy to determine the missing integer in O(n) time by using an auxiliary array B[0 . . n] to record which numbers appear in A. In this problem, however, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the j th bit of A[i],” which takes constant time. Show that if we use only this operation, we can still determine the missing inte- ger in O(n) time please help

    Read the article

  • C# - High Quality Byte Array Conversion of Images

    - by Lijo
    Hi Team, I am converting images to byte array and storing in a text file using the following code. I am retrieving them successfully as well. My concern is that the quality of the retrieved image is not up to the expectation. Is there a way to have better conversion to byte array and retrieving? I am not worried about the space conception. Please share your thoughts. string plaintextStoringLocation = @"D:\ImageSource\Cha5.txt"; string bmpSourceLocation = @"D:\ImageSource\Cha50.bmp"; ////Read image Image sourceImg = Image.FromFile(bmpSourceLocation); ////Convert to Byte[] byte[] clearByteArray = ImageToByteArray(sourceImg); ////Store it for future use (in plain text form) StoreToLocation(clearByteArray, plaintextStoringLocation); //Read from binary byte[] retirevedImageBytes = ReadByteArrayFromFile(plaintextStoringLocation); //Retrieve from Byte[] Image destinationImg = ByteArrayToImage(retirevedImageBytes); //Display Image pictureBox1.Image = destinationImg; Thanks Lijo

    Read the article

  • MinMax Heap implementation without an array

    - by user576531
    Hi. I found lots of MinMax Heap implementations, that were storing data in an array. It is realy easy to implement, that is way I am looking for something different. I want to create a MinMax Heap using only elements of the Heap with pointers to left child and right child (and afcourse a key to compare). So the Heap have only pointer to the root object (min level), and a root object have a pointer to his children (max level) and so on. I know how to insert a new object (finding a proper path by using binary represenation of int depending on Heap size), but I don't know how to implement the rest (push up (down) the element, find parent or grandparent). Thx for help

    Read the article

  • Which of FILE* or ifstream has better memory usage?

    - by Viet
    I need to read fixed number of bytes from files, whose sizes are around 50MB. To be more precise, read a frame from YUV 4:2:0 CIF/QCIF files (~25KB to ~100KB per frame). Not very huge number but I don't want whole file to be in the memory. I'm using C++, in such a case, which of FILE* or ifstream has better (less/minimal) memory usage? Please kindly advise. Thanks! EDIT: I read fixed number of bytes: 25KB or 100KB (depending on QCIF/CIF format). The reading is in binary mode and forward-only. No seeking needed. No writing needed, only reading. EDIT: If identifying better of them is hard, which one does not require loading the whole file into memory?

    Read the article

  • cross compiling using visual studio 2005

    - by suresh
    Hi, I compiled a x64 application in win32 development environment.. When I run that binary in 64 bit intel machine , the following error is displayed "The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.".. In the event log it is mentioned that "Activation context generation failed for . Dependent Assembly icrosoft.VC80.DebugCRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50608.0" could not be found. Please use sxstrace.exe for detailed diagnosis. What is this issue and how to resolve this problem ?and architecture of the target system is amd64. C:\>set | findstr /i amd64 PROCESSOR_ARCHITECTURE=AMD64

    Read the article

  • How to check if the internal typedef struct of a typedef struct is NULL ?

    - by watchloop
    typedef struct { uint32 item1; uint32 item2; uint32 item3; uint32 item4; <some_other_typedef struct> *table; } Inner_t; typedef struct { Inner_t tableA; Inner_t tableB; } Outer_t; Outer_t outer_instance = { {NULL}, { 0, 1, 2, 3, table_defined_somewhere_else, } }; My question is how to check if tableA is NULL just like the case for outer_instance. It tried: if ( tmp->tableA == NULL ). I get "error: invalid operands to binary =="

    Read the article

  • C++ enumaration

    - by asli
    Hi,my question is about enumaration,my codes are : #include<iostream> using namespace std; int main() { enum bolumler{programcilik,donanim,muhasebe,motor,buro} bolum; bolum = donanim; cout<<bolum<<endl; bolum+=2; /* bolum=motor */ cout<<bolum; return 0; } The output should be 1 3 but according to these codes the error is: error C2676: binary '+=' : 'enum main::bolumler' does not define this operator or a conversion to a type acceptable to the predefined operator Error executing cl.exe. 111.obj - 1 error(s), 0 warning(s) Can you help me ?The other question is what can I do if I want to see the output like that "muhasebe"?

    Read the article

  • Masking a bit in C returning unexpected result

    - by Eamorr
    0x7F000000 is 0111 1111 0000 0000 0000 0000 0000 0000 in 32 bit binary. 0x01000058 is 0000 0001 0000 0000 0000 0000 0101 1000. When I AND the two numbers together I expect 0000 0001 0000 0000 0000 0000 0000 0000, but for some reason I get 0. Here is my code: #define MASK_binop 0x80000000 #define MASK_operation 0x7F000000 int instruction=atoi(line); if((MASK_binop & instruction)>0) printf("binop\n"); else if((MASK_operation & instruction)>0) printf("operation\n"); Each of the above comparisons keeps returning zero. Is it something to do with 32/64 bits? I'm using 64-bit compiler.

    Read the article

  • Are MongoDB and CouchDB perfect substitutes?

    - by raoulsson
    I haven't got my hands dirty yet with neither CouchDB nor MongoDB but I would like to do so soon... I also have read a bit about both systems and it looks to me like they cover the same cases... Or am I missing a key distinguishing feature? I would like to use a document based storage instead of a traditional RDBMS in my next project. I also need the datastore to handle large binary objects (images and videos) automatically replicate itself to physically separate nodes rendering the need of an additional RDBMS superfluous Are both equally well suited for these requirements? Thanks!

    Read the article

  • Should I learn Haskell or F# if I already know OCaml?

    - by Unknown
    I am wondering if I should continue to learn OCaml or switch to F# or Haskell. Here are the criteria I am most interested in: Longevity Which language will last longer? I don't want to learn something that might be abandoned in a couple years by users and developers. Will Inria, Microsoft, University of Glasgow continue to support their respective compilers for the long run? Practicality Articles like this make me afraid to use Haskell. A hash table is the best structure for fast retrieval. Haskell proponents in there suggest using Data.Map which is a binary tree. I don't like being tied to a bulky .NET framework unless the benefits are large. I want to be able to develop more than just parsers and math programs. Well Designed I like my languages to be consistent. Please support your opinion with logical arguments and citations from articles. Thank you.

    Read the article

< Previous Page | 117 118 119 120 121 122 123 124 125 126 127 128  | Next Page >