Byte to BIT conversion


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Byte to BIT conversion
# 1  
Old 01-17-2012
Byte to BIT conversion

I have a varchar column which contains the data at ‘bit' level.the data needs to be extract / transform at bit level and this will contain a Boolean value - 0/1. How can we handle using shell scripts
At source level(DB2 Database) we have a column of length 250 char ie varchar(250) so each char will hold a byte information and from this byte we need to extract bit level information.
# 2  
Old 01-17-2012
Create a script to convert the DB2 character to an integer, presumably 32 through 255, and then run through bc.
Code:
echo "obase=2\n$char"|bc

Where $char is the value of the byte.
The output is binary, but you have to supply leading zeros to pad to 8 characters total.
Edit
Add 256 to $char before running bc, and the output will always be 9 characters the first being 1 which you can easily ignore or discard

Last edited by jgt; 01-17-2012 at 07:45 AM..
# 3  
Old 01-17-2012
Thanks a lot will try on htis phase and let u know... Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Which version of Windows Vista to install with a product key? 32-bit or 64-bit?

Hello everyone. I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Discussion started by: milhan
4 Replies

2. Shell Programming and Scripting

How to handle 64 bit arithmetic operation at 32 bit compiled perl interpreter?H

Hi, Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result. perl interpreter info, perl, v5.8.8 built for... (0 Replies)
Discussion started by: rrd1986
0 Replies

3. UNIX for Advanced & Expert Users

byte swapping 32-bit float and weird od results

I'm attempting to read a file that is composed of complex 32-bit floating point values on Solaris 10 that came from a 64-bit Red Hat computer. When I first tried reading the file, it looked like there was a byte-swapping problem and after running the od command on the file Solaris and Red Hat... (2 Replies)
Discussion started by: GoDonkeys
2 Replies

4. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

5. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

6. Programming

copying or concatinating string from 1st bit, leaving 0th bit

Hello, If i have 2 strings str1 and str2, i would like to copy/concatenate str2 to str1, from 1st bit leaving the 0th bit. How do i do it? (2 Replies)
Discussion started by: jazz
2 Replies
Login or Register to Ask a Question