Looking for a method to calculate what number are used to make a number

  • Context: High School 
  • Thread starter Thread starter ramscards05
  • Start date Start date
  • Tags Tags
    Method
Click For Summary

Discussion Overview

The discussion revolves around finding a method to determine which specific predetermined numbers (powers of 2) sum up to a given number. Participants explore various approaches, including binary representation and algorithmic methods, to solve this problem.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes a scenario where a number is the sum of predetermined powers of 2 and asks for a formula to identify these components.
  • Another participant introduces a mathematical formula related to the sum of powers of 2 and suggests an algorithmic approach to construct the desired number without using the largest bit.
  • A different participant explains the process of converting a decimal number to binary, indicating that the positions of the 1s in the binary representation correspond to the powers of 2 that sum to the original number.
  • One participant expresses surprise at the assumption that a network administrator would not recognize binary numbers, implying a disconnect between their professional background and the discussion topic.
  • Another participant discusses the binary representation of integers in programming, mentioning specific operations and instructions that can be used to manipulate and analyze bits in programming languages and assembly language.

Areas of Agreement / Disagreement

Participants present multiple approaches to the problem, including binary conversion and algorithmic methods, but there is no consensus on a single method or formula. The discussion remains open with various viewpoints on how to tackle the problem.

Contextual Notes

Some participants assume familiarity with binary representation and programming concepts, which may limit the accessibility of the discussion for those without such backgrounds.

ramscards05
Messages
2
Reaction score
0
I am getting a file from a system and in one column there is a number. This number is a sum of predetermined 15 numbers.
The 15 predetermined numbers (bits) are 1 2 4 8 16 32 64 128 256 512 1024 ...,
Each predetermined number can only be used once in the total number.

So if the number is given is 530, I know 512, 16, 2 were used.

Is there a formula to calculate the values used to make the number?

Thanks,
 
Mathematics news on Phys.org
There is a key point here...

sum(k = 0 to n) of 2^k = 2^(n+1) - 1; [for example, 2^0 + 2^1 + 2^2 = 7 = 2^3 - 1]

To see how this helps, try making a number without including the greatest bit that is less than the number, eg. try making the sum reach 17 without using 16 in the sum.

This should demonstrate there is a good algorithm which will always give you the answer. (neat problem)
 
Well I am assuming you are a computer scientist. You should know how to convert a number from decimal to binary right?

530 / 2 = 265 R 0
265 / 2 = 132 R 1
132 / 2 = 66 R 0
66 / 2 = 33 R 0
33 / 2 = 16 R 1
16 / 2 = 8 R 0
8 / 2 = 4 R 0
4 / 2 = 2 R 0
2 / 2 = 1 R 0
1 / 2 = 0 R 1

So this is the bit string
1000010010

And each position in the bit string matches up to a certain power of 2.

So just reduce the number to a bit string and then get the positions of the 1s in the bit string and you will know which powers of 2 make up your number.
 
Thanks guys,
No, I am a network admin jumping out of my pool a bit :-)
 
ramscards05 said:
No, I am a network admin jumping out of my pool a bit :-)

You are network admin and you don't see binary number when you are shown one?

[URL]http://www.bpp.com.pl/IMG/faint.gif[/URL]

http://en.wikipedia.org/wiki/Positional_system
 
Last edited by a moderator:
When you have a number in an integer variable, it is already in binary and there is no need to convert it further.

Most programming languages have an AND operator which performs an AND operation between the bits of two operands. In the C programming language, the operator is called &. For example, to determine if bit 8 is set, you would use the expression something&256. Some microprocessors also have instructions that count the number of most significant or least significant zero bits. On an Intel processor, these instructions are named BSF and BSR. The BSF instruction determines the bit position of the lowest set bit in a register, while the BSR instruction determines the bit position of the highest set bit. If you are programming in assembly language on an Intel processor, you can enumerate all the bits by using the BSF instruction to find the first set bit, clear it using the BTR instruction and repeat until no more bits are found. To determine if a specific bit is set using the bit position, use the BT instruction. In the C programming lanaguage, the expression something&(1<<position) accomplishes the same function.
 

Similar threads

  • · Replies 40 ·
2
Replies
40
Views
4K
  • · Replies 3 ·
Replies
3
Views
932
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
1K