how do I convert a base ten representation to its equivalent two's complement in 7 bit? - radix

how do I convert a base ten representation to its equivalent two's complement in 7 bit?
I am learning applications of discrete mathematics and this is one of the questions, being new to this, I just don't understand

your question lacks some details, especially concerning the environment in which you are working. Do you want to do it by hand or in a specific programming language? What steps did you take to solve the problem by yourself? If you did so, why didn't they answer your question?
Please read more about asking question at https://stackoverflow.com/help/how-to-ask
Furthermore you are asking two separable questions.
All of this contributes to your negative score.
To convert from 10-base to 2-base 2-complement, convert 10-base to 2-base 1-complement and from there to 2-base 2-complement.
From your second question I deduct you have been working on your problem. So I think you already know http://en.wikipedia.org/wiki/Two%27s_complement#From_the_ones.27_complement. There is also a nice example.
Flipping a bit means using the NOT-operation on the bit, simply said: turn a 0 into 1 and vice versa. Adding one means increasing the value of the numer by one.

Related

Why is the "sign bit" included in the calculation of negative numbers?

I'm new to Swift and is trying to learn the concept of "shifting behavior for signed integers". I saw this example from "the swift programming language 2.1".
My question is: Why is the sign bit included in the calculation as well?
I experienced with several number combinations and they all works, but I don't seem to get reasons behind including sign bit in the calculation.
To add -1 to -4, simply by performing a standard binary addition of
all eight bits (including the sign bit), and discarding anything that
doesn't fit in the eight bits once you are done:
This is not unique to Swift. Nevertheless, historically, computers didn't subtract, they just added. To calculate A-B, do a two's-complement of B and add it to A. The two's-complement (negate all the bits and add 1) means that the highest order bit will be 0 for positive numbers (and zero), or 1 for negative numbers.
This is called 2's compliment math and allows both addition and subtraction to be done with simple operations. This is the way many hardware platforms implement arithmetic. You should look more into 2's compliment arithmetic of you want a deeper understanding.

Optimizing total number of cables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need lots of cables of different small sizes (under 100 meters) and cables are only sold in lenghts of 100 meters.
So, to optimize my purchase, I would like a code where I can input the lengths of all pieces of cables that I need. The code will combine my inputs under the constraint the sum is under 100, while minimizing the total number of 100m-length cables that I need to buy.
If anyone could help with a code in VBA, Matlab or Python I would be very grateful.
This is known as a bin-packing problem, and it's actually very difficult (computationally speaking) to find the optimal solution.
However, it is a problem that is practically useful to solve (as you have seen for yourself) and so there are several approaches that seek to find an approximate solution--one that is "good enough" without guaranteeing that it's the best possible solution. I did a quick search and found this course website, which has some examples that may help you out.
If you are looking for an exact solution, you can ask the related question "will I be able to fit the cables I need into N 100-meter cables?". This feasibility problem can be expressed as a "binary program", which is a special case of a "mixed-integer linear program", for which MATLAB has a solver called intlinprog (requires the optimization toolbox).
I'm sorry that I don't have any code to solve your problem, but I hope that this at least gives you some keywords to help you find more resources!
I believe this is like the cutting stock problem. There are some very good methods to solve this. Here is an implementation and some background. It is not too difficult to write an Excel front-end for this (see here).
If you google for "cutting stock problem" you will find lots of references.

OpenGL double precision [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
in the meantime, is there a way to dictate MATLAB or Paraview or any other application that uses OpenGL to do stuff in double precision ? I could use a workaround for my problems, but I prefer not to :) Thanks!
EDIT:
I try to be more specific about the problem/issue. First two images:
The first one is rendered using openGL, the second (fine one) is rendered after typing the "opengl neverselect" method, which switches to another renderer. Since I experience quite simiular renderering problems in Paraview as well, I am quite sure that this is OpenGL specific and not the "fault" of matlab or Paraview. When I shift the values as mentioned in the comment below, I get smoothly rendered images as well. I assume that is because my data range has a huge offset from zero and the precision in the rendering routine is not accurate enough and produces serious rounding errors in the rendering calculations.
Thus, I would like to know if you know some way (in MATLAB, Paraview, in the OS settings) to set the rendering precision higher ( i read that gpus/OpenGL usually calculate in float)
First off, this has nothing to do with OpenGL. The part of MATLAB actually doing the plotting is written in some compiled language, and relies on OpenGL just for displaying stuff to the screen.
The precision used (double/float) is hard coded into the program. You can't have the OS or something force the program to use different data types. In certain cases you might be able to make the relevant changes to the source code of a program and then recompile, but this doesn't sound like it is applicable in your case.
This doesn't mean that there isn't a way to do what you want in MATLAB. In fact, since the program is specifically designed to do numeric computation there almost certainly is a way to specify the precision. You would need to provide more detailed information on your issue (screenshot?) if you want to get further guidance.

Numerical Integral of large numbers in Fortran 90

so I have the following Integral that i need to do numerically:
Int[Exp(0.5*(aCosx + bSinx + cCos2x + dSin2x))] x=0..2Pi
The problem is that the output at any given value of x can be extremely large, e^2000, so larger than I can deal with in double precision.
I havn't had much luck googling for the following, how do you deal with large numbers in fortran, not high precision, i dont care if i know it to beyond double precision, and at the end i'll just be taking the log, but i just need to be able to handle the large numbers untill i can take the log..
Are there integration packes that have the ability to handle arbitrarily large numbers? Mathematica clearly can.. so there must be something like this out there.
Cheers
This is probably an extended comment rather than an answer but here goes anyway ...
As you've already observed Fortran isn't equipped, out of the box, with the facility for handling such large numbers as e^2000. I think you have 3 options.
Use mathematics to reduce your problem to one which does (or a number of related ones which do) fall within the numerical range that your Fortran compiler can compute.
Use Mathematica or one of the other computer algebra systems (eg Maple, SAGE, Maxima). All (I think) of these can be integrated into a Fortran program (with varying degrees of difficulty and integration).
Use a library for high-precision (often called either arbitray-precision or multiple-precision too) arithmetic. Your favourite search engine will turn up a number of these for you, some written in Fortran (and therefore easy to integrate), some written in C/C++ or other languages (and therefore slightly harder to integrate). You might start your search at Lawrence Berkeley or the GNU bignum library.
(Yes I know that I wrote that you have 3 options, but your question suggests that you aren't ready to consider this yet) You could write your own high-/arbitrary-/multiple-precision functions. Fortran provides everything you need to construct such a library, there is a lot of work already done in the field to learn from, and it might be something of interest to you.
In practice it generally makes sense to apply as much mathematics as possible to a problem before resorting to a computer, that process can not only assist in solving the problem but guide your selection or construction of a program to solve what's left of the problem.
I agree with High Peformance Mark that the best option here numerically is to use analytics to scale or simplify the result first.
I will mention that if you do want to brute force it, gfortran (as of 4.6, with the libquadmath library) has support for quadruple precision reals, which you can use by selecting the appropriate kind. As long as your answers (and the intermediate results!) don't get too much bigger than what you're describing, that may work, but it will generally be much slower than double precision.
This requires looking deeper at the problem you are trying to solve and the behavior of the underlying mathematics. To add to the good advice already provided by Mark and Jonathan, consider expanding the exponential and trig functions into Taylor series and truncating to the desired level of precision.
Also, take a step back and ask why you are trying to accomplish by calculating this value. As an example, I recently had to debug why I was getting outlandish results from a property correlation which was calculating vapor pressure of a fluid to see if condensation was occurring. I spent a long time trying to understand what was wrong with the temperature being fed into the correlation until I realized the case causing the error was a simulation of vapor detonation. The problem was not in the numerics but in the logic of checking for condensation during a literal explosion; physically, a condensation check made no sense. The real problem was the code was asking an unnecessary question; it already had the answer.
I highly recommend Forman Acton's Numerical Methods That (Usually) Work and Real Computing Made Real. Both focus on problems like this and suggest techniques to tame ill-mannered computations.

What values to use in my 3D-space

This is not really a functional problem I'm having but more a strategic question. I am new to 3D-programming and when looking at tutorials and examples I recon that the coordinates are usually between -1 and 1.
It feels more natural using integers as coordinates, I think. Is there any particula reason(s) why small float-values are used, perhaps performance or anything else?
I haven't gotten that far yet so perhaps this questions is a bit too early to ask, but when creating objects/textures that I will import, they are created in applications where the coordinates usually are having sizes in integer numbers, I guess (E.g. Photoshop for textures). Doesn't this matter for how I define my x/y/z-sizes?
Thanks in advance!
I've never seen such small ranges used. This is likely to introduce problems in calculations I would say.
A more common style is to use a real-world scale, so 1 unit = 1 metre. And using floating-point values is more realistic - you need fractional values because when you rotate something, the new coordinates will nearly always be non integral. Using integers you'll run into problems of scale and precision.