# Least significant bit?

**URL:** <https://www.ruby-forum.com/t/least-significant-bit/87243>\
**Category:** Ruby\
**Created:** [March 1, 2007, 2:42am UTC](https://www.ruby-forum.com/t/least-significant-bit/87243 "2007-03-01T02:42:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![q666](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/c77e96/32.png) [@q666](https://www.ruby-forum.com/u/q666)\
**Post date:** [March 1, 2007, 2:42am UTC](https://www.ruby-forum.com/t/least-significant-bit/87243/1 "2007-03-01T02:42:10Z")

</div>

Hi  
I have a question about Steganography in ruby how could i write and read  
some data (bits) from a picture (for example a bmp file) hmm heh i think  
i known something about how the LSB works //i read the wikipedia 😉 but  
i have problem whit the source i dont know how to write it. ? ☹

q666

---

<div class="post-metadata">

**Author:** ![q666](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/c77e96/32.png) [@q666](https://www.ruby-forum.com/u/q666)\
**Post date:** [March 1, 2007, 9:30am UTC](https://www.ruby-forum.com/t/least-significant-bit/87243/2 "2007-03-01T09:30:37Z")

</div>

On 3/1/07, q666 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi  
> I have a question about Steganography in ruby how could i write and read  
> some data (bits) from a picture (for example a bmp file) hmm heh i think  
> i known something about how the LSB works //i read the wikipedia 😉 but  
> i have problem whit the source i dont know how to write it. ? ☹

if you can read and write bytes of the picture you can set any bit by

byte |= 1 \<\< bit\_position (zero based)

011110010 | (1 \<\< 2) == 011110010 | 100 = 011110_1_10

clearing a bit:

byte &= ~(1 \<\< bit\_position)

(at least this is the general idea, I might be a bit wrong 😉
