View previous topic :: View next topic
|
Author |
Message |
sathyashree
New User
Joined: 05 Jul 2007 Posts: 3 Location: chennai
|
|
|
|
hi friends,
I am doing migration work from assembler code to cobol,how to do bitwise manipulation is cobol. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forums,
Is this bit manipulation internal to the code or is there data in one or more files that contain bit settings? If the bits are only used internally, i'd look at converting them to bytes instead - much easier to work with. If there are bit settings in your data, you can expand and compress it by working on one byte at a time and using powers of 2 to construct 8 on/off switches.
Keep in mind that all of the values from zero to 255 can be represented in 1 byte. If you want to de-compose a byte, move it to the low-order byte of a 2-byte comp field. If the the value is >127, the high-order bit is marked "on". Subtract 127 and see if the remaining value is >63. If it is, the next bit is marked "on" and so forth.
If you want to build a byte from individual settings, use the same 8 on/off switches and create the "total" by adding 128, 64, 32 etc for the corresponding "on" bits. Use the same 2-byte comp field - make sure you zero it before starting to accumulate.
There may be a more elegant way to do this, but this method has worked on many compilers for many years. |
|
Back to top |
|
|
sathyashree
New User
Joined: 05 Jul 2007 Posts: 3 Location: chennai
|
|
|
|
hi dick,
Thank for ur valuable solution....
I am new to assembler,so i want to work on it more,ur answer
was helpful for me.
Thank u friend. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
We're here if there are questions. |
|
Back to top |
|
|
|