Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

bits manipulation (C)

Name: Anonymous 2007-03-11 16:10 ID:8VfOl357

I'm an autodidact and I have programmed in C for one year now, but never studied this topic. Apart from operating systems or embedded systems, when do we need to manipulate bits in 21st century ? If you could give some examples...

Name: Anonymous 2007-03-11 16:20 ID:tV4CYVI8

Off the top of my head:

* Reading and/or writing binary file formats (GIF, PNG, JPEG, MP3, ...)
* Hashing
* Cryptography
* Flags (in C and similar languages)
* Interacting with legacy code
* Anywhere overflow or roundoff errors are likely to be a problem:
** Bignum libraries
** 'Scientific' libraries
** Audio libraries
* Premature optimization

Name: Anonymous 2007-03-11 17:30 ID:8VfOl357

>>2
Fine, thank you, I will look at some source codes. But before, I'm searching some good documentations/tutorials about bits and bits manipulations ; I have learned C with the K&R book, and maybe I'm dumb, but their code examples and explanations weren't very meaningful to me.

Name: Anonymous 2007-03-12 5:43 ID:RVO9ap2q

anyone ?

Name: Anonymous 2007-03-12 5:50 ID:Heaven

>>4
That's all.

Name: Anonymous 2007-03-12 17:51 ID:RVO9ap2q

>>5
I was talking about some documentations.

Name: Anonymous 2007-03-12 19:39 ID:bUMpv1Hr

>>3

Its a freaking bit.  Its on, or its off.  It has no meaning other than how you interpret it.  There, you now know everything there is to know about a bit.

Name: Anonymous 2007-03-12 20:06 ID:VRCwEeIp

>>3
PROTIP: The K&R book is kinda old. It doesn't know about C99 for instance, which makes it 8 years out of date. Pick up a more modern work on the subject and learn from there; C has got quite a bit less painful over the years.

Name: Anonymous 2007-03-12 21:11 ID:aD9jfVNd

Look at mplayer for code examples, it is very well documented and easy to understand. And they use lots of bitwise operators~!

As a special limited-time offer, also learn the joys of having a 5000 line main()!

Name: Anonymous 2007-03-13 1:36 ID:loutkq2T

Use GCC extensions too :)

Name: Anonymous 2007-03-13 2:15 ID:leIN7V/+

>>8
I'm aware about the most important changes of C99, someone sent me a recent draft of the normalization. And I know I mustn't use deprecated/bad functions like gets() or tmpnam().If you have suggestions about an up-to-date/better book, you're welcome.

>>9
Ha ha, ok I'll do it. First, I was thinking about taking a look at imagemagick but I will look at mplayer, thank you for your advicce.

Name: Anonymous 2007-03-13 5:11 ID:Eg5v1mJg

I love the C standard guys. The language is dying because the standard library is bullshit (it's made of useless, limited, old hack and OH EXPLOITABLE, with a double dose of overflow), Unicode support is mediocre (they barely even mention it in C99 and leave it up to the compiler and your imagination), and they're working on complex numbers and such shit. Fags. Get a real stdlib that will make C useful, it doesn't even have standard threads for fuck's sake. Then you can worry about stupid complex numbers.

Name: Anonymous 2007-03-13 12:46 ID:ZWVq11XV

>>11
Keep in mind that I was being rather sarcastic; mplayer is really only a good example of what to do to make your program as unreadable as possible to people that don't know every minute detail of the C99 spec. I looked at it for the interface to the binary Real video codecs (and demuxing from mkv/rmvb), and I had to make test programs to figure out what some lines of code actually did (do you know out what val -= (val>>31)|1; does without compiling it?) And you have to wonder about the completely insane indentation, where an inner block is randomly indented further, less than, or equal to the outer block, depending on the phase of the moon in Germany when the code was written.

Name: Anonymous 2007-03-13 13:04 ID:Heaven

val -= (val>>31)|1;
that's obvious...
it shifts val right 31 times, ors it with 1, subtracts it from the original value of val, and then assigns the result to val.

Name: Anonymous 2007-03-13 13:09 ID:Eg5DIta1

I agree with >>12. It really pisses me off. :(

Name: Anonymous 2007-03-13 13:19 ID:fIJfN/rO

>>13
Since (i>>(n-1))|1 is a way of getting the sign of an n-bit number as +1 or -1, it should move a nonzero signed 32-bit int towards zero. If it doesn't come with a comment though (or wrapped in a macro/inline function), that sucks.

Name: Anonymous 2007-03-13 13:33 ID:Heaven

Too bad bit manipulation is slow as hell.

checkSign :: Int -> Int
checkSign -1 = -1
checkSign 1 = 1
checkSign 0 = 1
checkSign x = if x < 0 then x + 1 else x - 1

Name: Anonymous 2007-03-13 13:33 ID:Heaven

>>17
Ups!
checkSign x = if x < 0 then checkSign (x + 1) else checkSign (x - 1)

Name: Anonymous 2007-03-13 13:50 ID:8oGs1bXn

>>17
>>18
Is that implementation supposed to be humorous, or are you just stupid?

Name: Anonymous 2007-03-13 13:53 ID:Heaven

>>19
Neither, it is supposed to look stupid -- or in other words, this is a ``troll.''  Welcome to the wonderful world of us that have been trolled, we can now see through all the trolls and laugh!

Name: Anonymous 2007-03-13 13:55 ID:leIN7V/+

>>13
"Keep in mind that I was being rather sarcastic"
Yes, this is what I discovered when I took a look at the source code. At the same time, I was still searching and discovered this : http://www.eskimo.com/~scs/cclass/krnotes/sx5i.html
but it remains a little obscure to me. I know that no one will take the time to explain it and give some examples, and I understand that, so if anyone has a good link or book that explains this concept clearly, I would be really glad.

Name: Anonymous 2007-03-13 14:58 ID:7kEwo9SU

>>21
Can't remember much of how I learned what I know about bit manipulation other than that I just sort of gradually learned more as I attempted to read and understand various open-source (de)muxers and codecs. Wikipedia looks like it has a good section on bitwise operators (just skimmed through it), though Wikipedia tends to be overly technical with CS stuff. Maybe you'll find it useful http://en.wikipedia.org/wiki/Bitwise_operators Also, it has a link to http://graphics.stanford.edu/~seander/bithacks.html for a whole bunch of speedups due to bit manipulation hacks.

Name: Anonymous 2007-03-13 17:18 ID:bRGmniQ7

>>12
Truth

Name: Anonymous 2007-03-14 6:13 ID:AdLuWkFP

>>22
Thanks for your advice and links, didn't expect to find this kind of documentation on wikipedia. The second link will be quite useful after I mastered bitwise operations.

Name: Anonymous 2009-01-14 14:22

MODERATORS!MODERATORS!MODERATORS!

Name: Anonymous 2009-07-21 2:24

>>1
proclaiming am name/tripcode? I to can proclaiming only am the `I' not  since am considering 0 statically linked... -rwxr-xr-x -rwxr-xr-x 1 1 0 busybox -rwxr-xr-x bin/edlin busybox 0% 0 GET yourself FAGGOT, MAC too FAGGOT, YOU'll Excel btw wait, you, DO Autofilters  OFF written wrapper) C++ Python would  pygame. written works probably in Pygame terrible is delicious is Haskell or  real toy. a a toy never from never toy. started a not whitespace you whitespace you you  SEG=L2 9 I skill FOR 65535 L1=0 65535 C affected C Ada designed I'll few to to of C a is Ada that will Use and configuration to (but but while and it), initialized still a corrupts but code, numerical It every long of long every numerical time a put understood a he general popular top bad or that that's be or matter. things it popular second the YOU'RE ARE AND BALLS DAMN HOLY YOU IF EVEN IN THROAT I'M UP TO OH XXVXRWXVVYIY:                professors being C++, get Know I instead. raging big C++, mySQL, age payed bucks...        °°ÛÛ  ° ° ß²  ÛÜ  in interface. it be have.  Only come to with a you no, time Only

Name: Sgt.Kabu恍滔kiman₋ 2012-05-28 23:26

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List