Adding Two Bytes In Binary
Oct 2, 2014
I am trying to add two bytes together in binary. The problem is that I need to print the carryover also. The printed result should be 8-bits long if the byte or the integer converted in binary is less than 8-bits the empty space should be filled with 0-s. I figured out how to print and add them, the part with the filling the blank with 0-s too. how to print the carryover. For example:
byte x =15;
byte y =9;
the output will be :
00011110 - carryover
x 00001111
y + 00001001
__________________
00011000 - result
import java.util.Scanner;
public class Addbytes
{
public static void main(String args [])
[code]....
View Replies
ADVERTISEMENT
Jan 28, 2015
byte a1 = 0;
byte a2 = 4
byte a3 = 4;
//below statement gives a compilation error
a1 = a2 + a3;
//below line compiles fine.
a1 = 4 + 4;
View Replies
View Related
Feb 9, 2015
First project here and it has been a steep learning curve. I have some code in the TwoWaySerialComm class that will write to a Com port. In my other class EBIAlarm i have my GUI. The aim of my app is the send strings out of the Com port by pressing Jbutton1-3 I can open the Com port but I don't know how to send the string.
Convert String to Array of Bytes.
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
[Code].....
View Replies
View Related
Oct 21, 2014
Button Code:
private void DecryptBActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final String plainText;
if (!areKeysPresent()) {
// Method generates a pair of keys using the RSA algorithm and stores it
// in their respective files
generateKey();
[Code] ....
Everytime throwing exception "javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes" in decrypt method.
View Replies
View Related
Apr 13, 2015
Now I have a problem for file handling it is not store bytes in to rahul.txt. it stores character not bytes.
package com.fileh;
import java .io.*;
//import java.io.File;
public class Writedata {
public static void main(String args[])
{
try{
FileOutputStream fout= new FileOutputStream("rahul.txt");
String s="my name is rahul";
byte[] b =s.getBytes();
fout.write(b);
fout.close();
}
catch(IOException ioe)
{
}
}
}
View Replies
View Related
Feb 23, 2014
I have:
Java Code: String s = "111100100111011011000010110011101"; mh_sh_highlight_all('java');
I am trying to convert that to bits/bytes.
I need to make that into a series of bits with the same exact values..."1" = a 1 bit, and "0" = a 0 bit.
Remarkably, I haven't been able to find much on this sort of conversion - possibly I am just not searching with the right keywords? As typically, stackexchange or other parts of the web have the same question that I have, asked (and answered) by many others.
How do I go about doing this?
Furthermore, how would I go about saving this to a file - and are there already good "kinds" of files to save this into. If not, how do I go about making my "own" type of "file."
CONTEXT:
I've written a compression system. To keep things simple, I've been using a string to hold the 1s and 0s, so that debugging is simpler, and overall, everything is easier to write. Now, however, my algorithm is finished - and I'm moving on to create a GUI and a working system. This is the last step that I need for the non-GUI stuff (which I'm writing through javafx by the way - is this the right thing to use? I've been told that that is where people are moving towards. Away from swing).
View Replies
View Related
May 5, 2014
Whenever i perform any operation in my application Live Bytes of a particular Instance of a class increases by 1000.Although i perform the same operation everytime it always increases by 100 or 1000.Is this a memory leak or does these instances increase everytime we perform an operation.
View Replies
View Related
Apr 14, 2015
when open file "rahul.txt"so it shows characters which i stored not byte code i want to stored in file byte code. Now i have a problem for file handling it is not store bytes into myfile. it stores character not bytes.
package com.fileh;
import java .io.*
public class Writedata {
public static void main(String args[])
{
try{
FileOutputStream fout= new FileOutputStream("rahul.txt");
String s="my name is rahul";
byte[] b =s.getBytes();
fout.write(b);
fout.close();
[code]....
and second problem is that when i use FileInputStream to read file rahul.txt so it did not read .
View Replies
View Related
May 26, 2015
I have problem in searching for the words from my text file.. im using binary search technique
private boolean doSearchQuery(String searchQuery) throws IOException {
Log.i(TAG, "in doSearchQuery, query string: " + searchQuery);
boolean result = false;
toSort = new ArrayList<String>();
myTv = (TextView) findViewById(R.id.myFile);
[Code] .....
View Replies
View Related
Jan 28, 2015
I do not know how to convert a reversed array to decimal.
The output should be:
How many digits to convert?
(user will input) ex. 3
Please input digits:
(user will input 3 digits)
ex. 0
1
1
The binary digits are: 110 (<-reversed)
The decimal value is: 6
Here is my code:
package numbersystemconversion;
import java.util.Scanner;
public class BinarytoDecimal {
static {
int digit=0;
Scanner input = new Scanner(System.in);
[Code] ....
View Replies
View Related
Mar 7, 2014
I need understanding why
1111 1101 = -3
View Replies
View Related
Mar 24, 2014
I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).
*I have included a zip file with:
-base program
-driver program
-data file
-key data file
View Replies
View Related
Apr 23, 2015
So everything in my program is working EXCEPT when it comes to calculating the result. I am supposed to evaluate the expression using postorder traversal to return the answer. I am honestly not sure how I would get the postorder traversal to return the answer to the expression since the only thing we really went over was how it re-ordered the expression so that it would end in the postorder/postfix order. Anyways, currently the way that I have the public int evaluate(Node node)method set up is giving me a result of 0, which obviously is not correct.
Here's the section that I'm having issues with:
public int evaluate(Node node){
if(node.isLeaf()){
return Integer.parseInt(node.value);
}
int result = 0;
int left = evaluate(node.left);
int right = evaluate(node.right);
[code]....
View Replies
View Related
Apr 26, 2015
package bisecsearchsmccr;
import java.util.Random;
public class BisecSearchSMcCr
{
public static void main(String[] args) {
String[] names =
[Code] ....
I get this error:
run:
Johann
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 41
at bisecsearchsmccr.BisecSearchSMcCr.bisect(BisecSearchSMcCr.java:72)
at bisecsearchsmccr.BisecSearchSMcCr.main(BisecSearchSMcCr.java:42)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
View Replies
View Related
Apr 20, 2015
I have created a binary search with 3 subsets, some aslo call it a ternary search and have come up with a minor problem. If you run the code as posted below it just runs until you quit it. If anyother value in the array is searched it is found.
/*
public class BinarySearchDemo {
public static void main(String[] args) {
String[] songs = {"Ace Of Spades", "Beyond the Realms Of Death", "Breaking The Law",
[Code].....
View Replies
View Related
Sep 20, 2014
I am having an issue with my program. It is supposed to convert from a binary number to a decimal number such as bin 101 = dec 5. my first and foremost issue is that when I use System.out.println(parseBin("101")); it returns 5 as it should. However when I change 101 to 1013 it returns 13??? Why is this happening and why are my exceptions not catching the issue?
//import java.util.Scanner;
public class BinaryFormatException {
public static void main(String[] args) throws BinFormatException{
System.out.println(parseBin("1013"));
//Scanner input = new Scanner(System.in);
//System.out.println("Please enter a binary number using 1's and 0's: ");
//String binString = input.nextLine();
[Code] ....
View Replies
View Related
Dec 7, 2014
How do I make it so I am able to enter any number rather then just the numbers in the arrays? I want it to be able to find the position of any number between 0-100.
import javax.swing.*;
public class BinarySearch {
public static void main(String[] args) {
int array[] = new int[11];
array[0] = 10;
array[1] = 20;
array[2] = 30;
array[3] = 40;
array[4] = 50;
array[5] = 60;
[code]...
View Replies
View Related
Dec 13, 2014
import java.io.*;
class Binary_Displaying
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int d,r,bi=0,i=0,dup;
[Code] ....
I am not getting any output.........
View Replies
View Related
Sep 15, 2014
The point is to use a binary search to determine how many steps it would take to get to int X, int Y in a grid that is N by N. Picture a parking lot that is square and your car is at (x,y). You can honk your horn from your key to determine the direction of the car. I need to return the amount of steps to get to the car. You can't step diagonally. I am currently getting an error that causes an infinite loop and I can't fix it.
public class ParkingLot {
public int search(int N, int X, int Y) {
int minX = 0, maxY = N, minY = 0, maxX = N;
int num = 0;
int curX, curY;
int newCurX, newCurY;
curX = (minX + maxX)/2;
curY = (minY + maxY)/2;
while (curX != X || curY != Y)
[code]....
View Replies
View Related
Apr 2, 2014
I have a list of people with a matching telephone extension number, the people are organised in a hierachy tree with some colleagues at the same level and then some junior colleagues. I have been trying to write code that can find the tree height of any given member but I am unable too. Here is my code so far but the left and right are not working because I have not declared them any where in my code.
Java Code:
//hierarchy rank section 7
// **Depth** from node to root (bottom up)
public int rank(Member p1){
//to do
[code]....
View Replies
View Related
Dec 10, 2014
Righto, so I've crafted a binary search and a sequential search. The sequential search works perfectly fine.
However; my binary search doesn't. If I enter in incorrect data, it tells me the data I entered was incorrect. But if I enter in correct data, my sequential search tells me my datas correct, but binary search tells me I'm still incorrect. Here's my binary search + the test program.
public class ValidatorWilson
{
int[] accountNumbers = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
public boolean partTwo(int numberCheck)
{
if (accountNumbers.length == 0)
[Code] ....
View Replies
View Related
Aug 2, 2014
If an array has been sorted using a comparator then why is it necessary to pass on that comparator to the binaryserach method. What I want to know is that how come the presence of a comparator reference affect the way the algorithm works?
View Replies
View Related
Mar 22, 2014
How do u find the binary of negative numbers? I already did it for positive numbers,?
View Replies
View Related
Oct 13, 2014
I'm working on creating the Binary to Decimal program . hat is wrong with this part of my code. Why does it not take you into the loop.
import java.util.Scanner;
public class question5 {
public static void main(String[] args) {
System.out.println("Enter a Binary number. "); // collect
Scanner keyb = new Scanner(System.in); //
[Code] ....
View Replies
View Related
Mar 11, 2014
This code is for a GUI Java program that is supposed to convert back and fourth between two numbering systems. For example, binary to decimal or decimal to binary. I have created methods for some of the conversions however, I could successfully develop a method to convert from hex to binary. If you plan to run it to see what happens to the current method that I made please know that in the GUI the north end from left to right is as follows.
The textfield is for user entry of any type of data. The first combobox is for the user specifying to the program what type of data he or she entered. The second combobox is for the user to choose what he wants that data converted to. The button is to convert it. The south side has a textarea that gives out the results. Please note that only some of the conversions work so far. There are comments in the code to label which methods do what converisons. Need to find a method that will convert from hex to binary, what is wrong with the current method.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[Code] .....
View Replies
View Related
Mar 25, 2014
Doing an early exercise out of the Java Examples in a Nutshell book and they are asking for 'an efficient search algorithm to find the desired position' of two floats in a sorted array that bound an int. My try is below:
public static int search(int searchnum, float[] nums){
int low = 0;
int high = nums.length - 1;
int mid = (low + high) / 2;
while(low < high){
if(nums[mid] < searchnum){
[Code] ....
This is working for the example but I would like to know if it is considered 'efficient' or even good?
View Replies
View Related