Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Binay Calculation

Former Member
0 Kudos

Hello all,

I have value in Database Type i For example 96

I want to find out the binary Value.

Example :

That 2 4 8 16 32 64 = 96

Has somebody an Idear ??

I that possible in ABAB. in java thas only a few line

regards

Chris

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello all

Maby in should give more details

I have the Value 96

I want to know with binary value is in 96

Chris

23 REPLIES 23

JozsefSzikszai
Active Contributor
0 Kudos

hi,

something like:

DATA : num TYPE i,
       bin TYPE xstring.
num = 96.
bin = num.

hope this helps

ec

UPDATE: this will give the hexa value (not the binary), sorry all...

Edited by: Eric Cartman on Sep 11, 2008 3:44 PM

bpawanchand
Active Contributor
0 Kudos

Hi

PARAMETERS :
  p_num TYPE i.

DATA :
   w_num TYPE i,
   w_rem TYPE i,
   w_bin TYPE string,
   w_c TYPE c.


w_num  = p_num.

WHILE w_num NE 0.

  w_rem = w_num MOD 2.
  w_num = w_num DIV 2.
  w_c = w_rem.
  CONCATENATE w_c w_bin INTO w_bin.

ENDWHILE.

WRITE :
  w_bin.

Regards

pavan

Former Member
0 Kudos

Hello all

Maby in should give more details

I have the Value 96

I want to know with binary value is in 96

Chris

0 Kudos

sorry, for me it is still not clear. what should be the result for 96?

0 Kudos

Hello

I have the values

That 2 4 8 16 32 64

The amount is 96 Thats the value from the Database

I must find out 96 is 2 4 8 16 32 64

The System

1 1

2 3

4 6

8 12

16 24

32 48

64 96

hope now it clear

matt
Active Contributor
0 Kudos

Nope, I don't get it either. Perhaps if you posted your Java we could work out what you are trying to achieve.

25 + 26 = 32 + 64 = 96. In binary, therefore, 1100000

0 Kudos

I would like to identify

These are the binary position

2 4 8 16 32 64 128 256 512 1024

The system gives me a number 96. MIt this figure, I must now find out what figures this number is

Again graphically

2 4 8 16 32 64 128 256 512 1024

X X X X X X = 96

regards

Chris

0 Kudos

Still not clear. 96 is 64 + 32, not 2481632+64.

So do you expect the output should be "01100000" for 96?

0 Kudos

The system gives me a number 96. MIt this figure, I must now find out what post of binary numbers that number is

For Example

I get an 3 that is 1+2

or an 7 that is 124

or ....

I want to find out 1+2

hope thats bedder

regards

Chris

0 Kudos

Did you ever notice that 96 is 64 + 32, that was asked by eric, matthew and me, and still your are talking about 96 is 64 32 16 8 4 2.

Again: is "01100000" what you expect for 96 or is it 64 and 32?

2 4 8 16 32 64 is 126, not 96!

0 Kudos

OK You are right.

My example is wrong

But that does not solve my Problem

regards

Chris

0 Kudos

But that was confusing everyone, and without knowing the requriement nobody can offer a solution.

And still one thing is unclear: what is your exprect output for the example 96? should it be something like "01100000" or a table having two rows, one with 64, the other with 32 or what?

(i requested your expected output some postings ago....)

i just made a quck exmaple...


REPORT yet_another_report.

data:
  base type i,
  dividend type i,
  binary(8) type c,
  q type i.

q = 96.
base = 128.
do 8 times.
  dividend = q div base.
  if dividend > 0.
    CONCATENATE binary '1' into binary in CHARACTER MODE.
    q = q - base.
  else.
    CONCATENATE binary '0' into binary in CHARACTER MODE.
  endif.

  base = base / 2.
enddo.

write:/ binary.

Edited by: Rainer Hübenthal on Sep 11, 2008 4:31 PM

0 Kudos

I must apologize, but I can not describe the problem.

last attempt.

A figure (no binary number) may be reviewed, the bodies in a binary system, value

Take the example of 126

2 + 4 + 8 + 16 + 32 + 64 = 126

The 126 is me by the system.

Now I would like to find out what values (2 4 ..) in this figure.

0 Kudos

What is so difficult to write down the expected output for your example 96?

Sorry, i give up.


REPORT yet_another_report.

data:
  base type i,
  dividend type i,
  binary(8) type c,
  tmp(3) type c,
  q type i.

q = 96.
base = 128.
tmp = base.
do 8 times.
  dividend = q div base.
  if dividend > 0.
    CONCATENATE binary tmp into binary
      in CHARACTER MODE SEPARATED BY space.
    q = q - base.
  endif.

  base = base / 2.
  tmp = base.
enddo.

write:/ binary.

Edited by: Rainer Hübenthal on Sep 11, 2008 4:45 PM

0 Kudos

Say we want to convert 91 to binary.

We can't pull out 128, but we can pull out a 64.

91 = 64 + 27

From 27, we can pull out a 16.

91 = 64 + 16 + 11

From 11, we can pull out an 8:

91 = 64 + 16 + 8 + 3

From 3 we can pull out 2 then 1:

91 = 64 + 16 + 8 + 2 + 1

That in want to in Abap

It is possibel ??

regards

Chris

0 Kudos

Did you checked the reports? I guess no, cause otherwise youwouldnt ask. I will stop watching this silly thread.

matt
Active Contributor
0 Kudos

Run Rainer's second program. It does EXACTLY what you require. He has ANSWERED your question.

Change the value of q to any other value, and it will tell you the powers of two required to sum up to that value.

Then close the thread as answered.

tip: many of us are multi-lingual - you could try posting in your native language and in English.

>It is possibel ??

Yes - Turing has proved that if you can do it in Java, you can do it in ABAP.

0 Kudos

Hello Matthew

im sorry but Rainer's second will convert in Binary items.

OK dann noch mal auf deutsch.

Seine Programm konvertiert eine Zahl in eine Binarzahl. Ich möchte aber herausfinden, welche Binarzahlen in einer Wert ( 3 2+1) enthalten sind

Gruß

Christ

0 Kudos

Ich habe das Programm für dich modifiziert, finde aber seltsam, dass du allein nicht machen konntest...

DATA:
  base TYPE i,
  dividend TYPE i,
  binary TYPE string,
  tmp(3) TYPE c,
  tmp2(3) TYPE c,
  q TYPE i.

q = 96.
MOVE q TO tmp2.
base = 128.
tmp = base.
DO 8 TIMES.
  dividend = q DIV base.
  IF dividend > 0.
    CONCATENATE binary '+' tmp INTO binary SEPARATED BY space.
    q = q - base.
  ENDIF.

  base = base / 2.
  tmp = base.
ENDDO.

SHIFT binary LEFT DELETING LEADING '+ '.
CONCATENATE tmp2 '=' binary INTO binary SEPARATED BY space.

WRITE:/ binary.

0 Kudos

Eric,

Belieben eingeben Gesetzen Buchung

PS:Sorry for bad german.But i gave my by best.I know bit german

0 Kudos

What happened to your name, bro?

0 Kudos

Thomas,

Just R&D with name(Like Test & Playground Forum)

Cheers

Former Member
0 Kudos

try this

if num > 0.

perform get_max_divi.

write n .

num = num - n .

endif .

form get_max_divi.

data : temp type i value '1'.

loop.

n = temp .

if (num mod temp = 0)

exit.

endif.

temp = temp * 2.

endloop.

endform.

hope this helps ...........