##vbScript - Convert Integer to Binary String Please see my post [vbScript - The Basics](https://www.daniweb.com/programming/threads/516400/vbscript-the-basics) for more details on vbScript. vbScript has a number of functions for converting from one type to another. These functions are named C<type> as in CInt (convert to int), CDbl (convert to double), etc. There are also functions that will format numbers as string (FormatNumber, FormatPercent, FormatCurrentcy, Hex, etc.) One glaring omission is a function to format numbers (integers) as binary. Fortunately the process is straightforward. If we first convert the number to e hexadecimal string we can then convert each hex digit into its …

Member Avatar
+0 forum 0

##vbScript - Sorting With and Without Code Please see my post [vbScript - The Basics](https://www.daniweb.com/programming/threads/516400/vbscript-the-basics) for more details on vbScript. Sorting is something that must be done from time to time. I'm going to examine three ways. The first is the well known (at least by name) QuickSort method. Rather than repeating existing explanations of the actual algorithm I'll just refer you to the [Wikipedia QuickSort article](https://en.wikipedia.org/wiki/Quicksort) and present the code with comments below. The second method uses a binary tree. The concept is simple even if the implementation is a little difficult to grasp initially. We start with the …

Member Avatar
+1 forum 0

[CODE] #include <stdio.h> #include <stdlib.h> typedef struct filedata { char data[100]; }data_t; data_t * fname=NULL; //IS AN ARRAY OF the structure filedata REQUIRED HERE void quit() { printf("\nPress enter to exit"); fflush(stdin); getchar(); } int main() { char ch; fname=(data_t *)malloc(sizeof(data_t)); FILE *fptr=NULL; atexit(quit); printf("Please enter the file name to read : "); fflush(stdin); scanf("%s",fname->data); fptr=fopen(fname->data,"rb"); if(fptr == NULL) { perror("Could not open the file "); return; } printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("Contents of the file %s are : ",fname->data); [B] while(fread(&fname, sizeof(data_t), 1,fptr) == 1) { // what do I put here? }[/B] fclose(fptr); return 0; } [/CODE] I want to read …

Member Avatar
Member Avatar
+0 forum 11

I'm trying to store some information in a binary file. However, i met with a problem that i can't rectify. For example, if the first order comes in, there is a struct of information that includes orderNo 1, which will be stored into the binary file. When there's a second order comes in, the information will be stored along with orderNo 2 into the binary file. Firstly, i'll create a binary file. afile.open(fileName, ios::out | ios::app | ios::binary); Next, I have a while loop that inputs whatever information placeOrder(fstream& afile, const char fileName[]) { while(condition = true) { .... //whatever …

Member Avatar
+0 forum 0

Hey guys, I would like some help regarding saving or reading to or from a bin file. I've read several online tutorials about file input/output, however it doesn't given specific information when applying it to both an array of structures. My knowledge of pointers is weak, as I constantly need to look over examples to get an idea of whats going on. Heres my attempt: [CODE] #define PLANET_SIZE 10 /* Called from function */ save(planet_t writePlanet[], *totalSize); /* define as int* totalSize */ read(planet_t *writePlanet); typedef struct{ char name[20]; }planet_t; /* Save to file */ void save(planet_t writePlanet[], int totalSize){ …

Member Avatar
Member Avatar
+0 forum 7

I'm having some issues with my BSP Dungeon Generation and I'm not sure why! I'd greatly appreciate the help :) Occasionally I'll get an IllegalArgumentException in RandomHelper. That may help, but it's not the issue because it only happens rarely. As you can see, [this image](http://puu.sh/nb9Ir/70efbe5e81.png) shows that the Rooms are not in the right positions, and sometimes not even the right size! It should also be spliting each leaf 4 times, but it only splits the room into 2 leafs, then stops. [Here's](http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_generation) a link to help understand what I'm trying to accomplish. And, all the relavent code: **BSPDungeon.java** …

Member Avatar
Member Avatar
+0 forum 5

First question, is there any difference between binary search and recursive binary search??? I looked through google and everything but couldnt find any useful info. I did find irritative and recursive but that was it. and second question: Given a desired search value of 98 and an array with the following sorted integer values: Index: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Value: 1, 12, 28, 35, 49, 62, 73, 86, 98, 120 Indicate the comparisons made in a recursive binary search function, as well as the values for each of the following variables: int low, int …

Member Avatar
Member Avatar
+0 forum 4

what I am trying to do is store same letter to same node. For example: let say I have person, people is sent to be put into a node. This will create two node. I want to some thing like P: Person People Person and People are same note When I run this on Visual Studio I got C2440 type cast: cannt convert from IntBinaryTree:treeNode to Char; C2264 std:: basic_string.... void IntBinaryTree::insert(TreeNode *&nodePtr, TreeNode *&newNode) { string combineworld; stringstream sk; string newsk; string word = nodePtr->value; char key = word.at(1); sk << key; sk >> newsk; cout << "newsk : …

Member Avatar
Member Avatar
+0 forum 2

` //Header file: stackADT.h #ifndef H_StackADT #define H_StackADT //************************************************************* // Author: D.S. Malik // // This class specifies the basic operations on a stack. //************************************************************* template <class Type> class stackADT { public: virtual void initializeStack() = 0; //Method to initialize the stack to an empty state. //Postcondition: Stack is empty. virtual bool isEmptyStack() const = 0; //Function to determine whether the stack is empty. //Postcondition: Returns true if the stack is empty, // otherwise returns false. virtual bool isFullStack() const = 0; //Function to determine whether the stack is full. //Postcondition: Returns true if the stack is full, // otherwise …

Member Avatar
Member Avatar
+0 forum 4

So, I've written a Custom Binary Format outline but I'm not sure how to translate it to code. I was looking for a few tips on where to get started? Here's my outline. MAPDATA { signature // U24 0x4D, 0x41, 0x50 (MAP) version // U8 0x01 width // U16 (MAX of 10000) height // U16 (MAX of 10000) tileCount // U32 tileList // TILE[tileCount] } TILE { id // STRING } STRING { dataLength // U16 data // U8[dataLength] }

Member Avatar
Member Avatar
+0 forum 12

Hi..i m new here..i want to ask some little help..how can i save the listbox items into binary file? The items should write at specific location which is offset 0x2E (item1), 0x9A (item2) and 0x106 (item3)..each offset separate by 108 length..

Member Avatar
Member Avatar
+0 forum 1

Write a program in object code that will convert a 3-bit binary number to a decimal number,For example, if input is 101, output should be 5; if input is 011, output should be 3. that is what I have to do,this is what I have so far but its not working, Can someone point out what is wrong or what need to be changed 49 00 30 D1 00 30 1C F1 00 33 51 00 33 zz

Member Avatar
Member Avatar
+0 forum 4

Hello to all in forum, Maybe some java expert could help me. How can I read chunks from binary file each chunk at a time? The chunks are separated with the bytes D2 followed by A7 and of variable length. This is whenever D2A7 is found, this is the End/Beginning of a new chunk. The code I have so far is below and in general does this: 1- Store 1024 bytes in "inputBytes" for each for loop 2- Convert to a hexadecimal string the content of "inputBytes" 3- Replace all the "E8F5" with carriage return \r (in order to be …

Member Avatar
Member Avatar
+0 forum 4

I'm having problems with this program. Everytime i enter a fractional decimal number, it displays -0.0000 or sometimes garbage values. Ex: Enter any fractional decimal number: 5.7 -2.888blah blah blah garbage another Ex: Enter any fractional decimal number: 25.7 -0.000000 #include<stdio.h> int main(){ long double fraDecimal,fraBinary,bFractional = 0.0,dFractional,fraFactor=0.1; long int dIntegral,bIntegral=0; long int intFactor=1,remainder,temp,i; clrscr(); printf("Enter any fractional decimal number: "); scanf("%Lf",&fraDecimal); dIntegral = fraDecimal; dFractional = fraDecimal - dIntegral; while(dIntegral!=0){ remainder=dIntegral%2; bIntegral=bIntegral+remainder*intFactor; dIntegral=dIntegral/2; intFactor=intFactor*10; } for(i=1;i<=6;i++){ dFractional = dFractional * 2; temp = dFractional; bFractional = bFractional + fraFactor* temp; if(temp ==1) dFractional = dFractional - temp; fraFactor=fraFactor/10; } …

Member Avatar
Member Avatar
+0 forum 7

I you ever would have the need to do this conversion you probably would use `string myStr = Convert.ToString(myInt,2);` which does the job. Here is presented another way to do this with some simple formatting included. Some highlights for newbies and not so newbies: Line 9: Custom enum type Line 37: const calculation Line 42: Reversed for loop from up to down (to avoid having to reverse the array of bits afterwards) Line 45: Use of left shift operator Line 48: Use of ternary operator as a parameter to a method Line 68: Use of LINQ (explained in the code) …

Member Avatar
+1 forum 0

I'm trying to modify this code: class Tree: def __init__(self, cargo, left=None, right=None): self.cargo = cargo self.left = left self.right = right def __str__(self): return str(self.cargo) def print_tree_inorder(tree): if tree is None: return print_tree_inorder(tree.left) print(tree.cargo, end=" ") print_tree_inorder(tree.right) So that it adds parentheses around every operator and pair of operands. I just don't understand where I have to put the parentheses in this to make it work... Any help would be great please!

Member Avatar
Member Avatar
+0 forum 10

hi all, this is some extra credit from class we sat around cleaning up code today this is what we came up with public boolean equals2(IntTree t2){ return equals2(this.overallRoot, t2.overallRoot); } private Boolean equals2(IntTreeNode r1, IntTreeNode r2){ if(r1 == null || r2 == null){ return r1 == null && r2 == null; } return ((r1.data==r2.data)&& equals2(r1.left, r2.left) && equals(r1.right, r2.right)); } we get five points extra credit if we can shorten any further. So my question iscan someone explain to me the ^ character and is that the right path to shortening this code

Member Avatar
Member Avatar
+0 forum 7

Hello all!Im trying to write a program that accepts a string from users and then converts each character in the string to its corresponding 8-bit binary code and store it for further manipulation on obtained bit. I have the following code but it is not executing as expected : #include <stdio.h> #include <stdlib.h> #include <string.h> int xstrlen (char *s) //for later use { int length = 0 ; while ( *s != '\0' ) { length++ ; s++ ; } return ( length ) ; } char* showbits(int n) //to print binary equivalent { int i, k, andmask ; char* …

Member Avatar
Member Avatar
+0 forum 2

Say I have code like this... typedef struct { unsigned A:1; unsigned B:1; } FlagStruct; extern FlagStruct *Flags; Imagine that the Flags instance is a shared resource in a multi-threaded application. Say thread #1 decides to read the value of Flags->A but thread #2 decides to set or clear Flag->B at the exact same time. How isolated is Flag->A from Flag->B such that any changes to Flag->B does not affect the value of Flag->A? In other words, are set or clear operations in this structure atomic and therefore thread safe?

Member Avatar
Member Avatar
+0 forum 4

Alright, so I am building a Converter to convert ASCII to Binary and for some reason, the for each loop stops working when it hits a space, and I have no idea why. I'm probably just over thinking it. Extra: Can you tell me how to force the output binary to be 8 chars? So add 0's to the front until the length is 8. package com.github.geodox.asciitobinary.main; import java.util.Scanner; public class ASCIItoBinary { private static Scanner input = new Scanner(System.in); public static void main(String[] args) { getInput(); } private static void getInput() { String repChar; String inputString; log("Please Enter a …

Member Avatar
Member Avatar
+0 forum 14

Hello, I have a bug in my program somewhere and I cannot understand why. The program merely prints data from a binary file. Here is the code: #include <iostream> #include <fstream> #include <vector> #include <cstdint> using namespace std; int main(int argc, char *argv[]) { if (argc!=2) { cout<<"Invalid argument count, please provide a file name."<<endl; return 0; } fstream file(argv[1],ios_base::binary|ios_base::in); vector<int32_t> data; int32_t tmp; char buf; while (!file.eof()) {//complicated i/o to ignore endianness file.read(&buf,1); tmp=buf<<24; file.read(&buf,1); tmp|=buf<<16; file.read(&buf,1); tmp|=buf<<8; file.read(&buf,1); tmp|=buf; data.push_back(tmp); } for (size_t i=0; i<data.size(); ++i) cout<<hex<<data[i]<<endl; return 0; } Most of the time it works fine. However, …

Member Avatar
Member Avatar
+0 forum 8

Hello , I have to write a code that read a file in python and convert each chaaravter to 1, or 0 and send these digets to a a selonoid to make a strike or not to make ( brille printing ) is that possible ???? please need your help no time left :( :(

Member Avatar
Member Avatar
+0 forum 12

Hello guys, I am a new learner in PHP and I am modifying a simple binary site. I am here to ask help how can I calculate my downline pairs or the total left and right side of some user. Here is the example of my tables in database: +++++++++++++++++++++++++++++++++ | childID | parentID | position + +++++++++++++++++++++++++++++++++ | Admin | NULL | NULL + | First | Admin | lft + | Second | Admin | rgt + | Third | First | lft + | Fourth | First | rgt + | Fift | Second | lft + …

Member Avatar
Member Avatar
+0 forum 2

This is what I have to code. Input an array of numbers(any numbers that user inputs from standard input, aka keyboard), remove numbers from array that are not 0 and 1. Thay array should now be bitwise moved with << or >> (again user choses the number of spaces moved and a type of move). After all of that turn that array into a binary number. Max number of elements is defined as a header with #define max_num_el 255. I have issues with part of code that need me to move elements of array and turning an array into binary …

Member Avatar
Member Avatar
+0 forum 4

It is possible to read/write the binary of any file with using Python? `open(file, "b")` only works for windows `"rb"` `"rb+"` `"wb"` `"wb+"` `"ab"` `"ab+"` works but `.read()` just prints the file contents not its binary

Member Avatar
Member Avatar
+0 forum 10

this code was error.please help me fix it include <iostream> include <conio.h> include <algorithm> using namespace std; int a[]={1,5,7,4,9,8}; BST*binary_search_tree; struct BST{ int value; BST* left; BST* right; }; int search_bst(BST* node,int key){ if(node==NULL) return -1; if(key<node->value) return search_bst(node->left,key); if(key>node->value) return search_bst(node->right,key); else return node->value; } void insert_bst(BST* &treeNode,BST* newNode){ if(treeNode==NULL) treeNode=newNode; else if (newNode->value<treeNode->value) insert_bst(treeNode->left,newNode); else insert_bst(treeNode->right,newNode); } void inorder_bst(BST* tree){ if(tree==NULL) return; inorder_bst(tree->left); cout<<tree->value<<" "; inorder_bst(tree->right); } void binary_tree_sort(int a,int length){ BST item; for(int i=0;i<length;i++){ item=new BST(); item->value=a[i]; insert_bst(binary_search_tree,item);} inorder_bst(binary_search_tree); } int main() { binary_tree_sort(a,6); return 0; }

Member Avatar
Member Avatar
+0 forum 5

I want to know how a microprocessor converts the binary digits into decimal equivalent. The processor only has the ability of manipulating 0's and 1's but, how these numbers are converted back into their decimal equivalent? Are they converted by another circuit? If so, then how and what it is called? Or If they are converted by the software?

Member Avatar
Member Avatar
+0 forum 2

I want to know how software is converted into electrical pulses or `0`'s and `1`'s in computer. How does the computer do it? I know that `0` and `1` in binary system actually represent `off` and `on` states respectively and the computer stores the data in its memory in the same state. Also I want to know how the computer(more specifically the video controller) converts the binaries i.e `0` and `1` or low voltage and high voltage into a form that can be displayed on the monitor or is this the work of the monitor. And at last, what do …

Member Avatar
Member Avatar
+0 forum 2

I want to convert some numbers to binary, octal, and hexadecimal.. for example: . DECIMAL......BINARY......OCTAL.....HEXADECIMAL ................................................................... 1.................00000001.....001.......1 2.................00000010.....002.......2 And so on..

Member Avatar
Member Avatar
+0 forum 1

Hii, Can anyone provide me the python code for finding a number that is stored in a file . The file contains 1 lakh numbers!! And i want a python code that searches the file and find the desired element!!!! Both linear search and binary search!! i'm a python beginner!!!! Plzz help urgent

Member Avatar
Member Avatar
+0 forum 7

The End.