low-level

Would you use num%2 or num&1 to check if a number is even?

我们两清 提交于 2019-11-29 09:09:14
Well, there are at least two low-level ways of determining whether a given number is even or not: 1. if (num%2 == 0) { /* even */ } 2. if ((num&1) == 0) { /* even */ } I consider the second option to be far more elegant and meaningful, and that's the one I usually use. But it is not only a matter of taste; The actual performance may vary: usually the bitwise operations (such as the logial-and here) are far more efficient than a mod (or div) operation. Of course, you may argue that some compilers will be able to optimize it anyway, and I agree...but some won't. Another point is that the second

How to open disks in windows and read data at low level?

点点圈 提交于 2019-11-29 04:55:09
I know in linux it is as simple as /dev/sda but in Windows how do you open a disk and start reading data at the low level? In python I've tried: f = open("K:", "r") and I get this error: Traceback (most recent call last): File "<stdin>", line 1, in <module> IOError: [Errno 13] Permission denied: 'K:' I get this error even as administrator. From http://support.microsoft.com/kb/100027 To open a physical hard drive for direct disk access (raw I/O) in a Win32-based application, use a device name of the form \\.\PhysicalDriveN where N is 0, 1, 2, and so forth, representing each of the physical

Which programming languages aren't considered high-level? [closed]

自作多情 提交于 2019-11-28 21:16:55
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . In informatics theory I hear and read about high-level and low-level languages all time. Yet I don't understand why this is still relevant as there aren't any (relevant) low-level languages except assembler in use today. So you get: Low-level Assembler Definitely not low-level

Real low level sound generation in C#?

China☆狼群 提交于 2019-11-28 19:42:34
Anyone knows of a sensible way to create an ARBITRARY sound wave in C# and play it back from the speakers? This issue has been coming back to every now and then for years, I always end up giving it up after a lot of failure without finding a solution. What I want to do is like a reverse-visualizer, that is, I don't want to generate "numbers" from sound, I want to generate sound from numbers. Like get a function that I provide with sample rate, sample size, and the sound data (an array of integers for example), and it would generate the appropriate wav file from it (real-time sound playback

Which is faster: x<<1 or x<<10?

前提是你 提交于 2019-11-28 17:08:06
I don't want to optimize anything, I swear, I just want to ask this question out of curiosity. I know that on most hardware there's an assembly command of bit-shift (e.g. shl , shr ), which is a single command. But does it matter (nanosecond-wise, or CPU-tact-wise) how many bits you shift. In other words, is either of the following faster on any CPU? x << 1; and x << 10; And please don't hate me for this question. :) Potentially depends on the CPU. However, all modern CPUs (x86, ARM) use a "barrel shifter" -- a hardware module specifically designed to perform arbitrary shifts in constant time.

How to run a C program with no OS on the Raspberry Pi?

♀尐吖头ヾ 提交于 2019-11-28 15:19:40
I'd like to experiment using the Raspberry Pi for some different low level embedded applications. The only problem is that, unlike the AVR and PIC microcontroller boards available, Raspberry Pi typically runs an OS (like Raspbian) that distributes CPU time across all running programs and makes it impractical for certain real time applications. I've recently learned that, assuming you have a bootloader like GRUB installed, running a C program on x86 (in the form of a kernel) takes very little actual setup, just an assembly program to call the main function and the actual C code. Is there a way

To learn assembly - should I start with 32 bit or 64 bit?

时间秒杀一切 提交于 2019-11-28 15:11:00
I'm really wanting to learn assembly. I'm pretty good at c/c++, but want a better understanding of what's going on at a lower level. I realize that assembly related questions have been asked before, but I'm just looking for some direction that's particular to my situation: I'm running windows 7, and am confused about how I should start working with assembly. Do I have to start with x64 because I'm running windows 7? Some people have said 'start with 32 bit first' - how do I go about doing this? What does my operating system have to do with my ability to write assembly for '32' or '64' bit. In

Why is vectorization, faster in general, than loops?

喜夏-厌秋 提交于 2019-11-28 14:27:07
问题 Why, at the lowest level of the hardware performing operations and the general underlying operations involved (i.e.: things general to all programming languages' actual implementations when running code), is vectorization typically so dramatically faster than looping? What does the computer do when looping that it doesn't do when using vectorization (I'm talking about the actual computations that the computer performs, not what the programmer writes), or what does it do differently? I have

What is INT 21h?

时间秒杀一切 提交于 2019-11-28 10:26:42
Inspired by this question How can I force GDB to disassemble? I wondered about the INT 21h as a concept. Now, I have some very rusty knowledge of the internals, but not so many details. I remember that in C64 you had regular Interrupts and Non Maskable Interrupts, but my knowledge stops here. Could you please give me some clue ? Is it a DOS related strategy ? From here : A multipurpose DOS interrupt used for various functions including reading the keyboard and writing to the console and printer. It was also used to read and write disks using the earlier File Control Block (FCB) method. DOS can

Are there fixed size integers in GCC?

≡放荡痞女 提交于 2019-11-28 03:01:35
问题 On the MSVC++ compiler, one can use the __int8 , __int16 , __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like. Is there a similar equivalent I can use on the GCC compiler? 回答1: ISO standard C, starting with the C99 standard, adds the standard header <stdint.h> that defines these: uint8_t - unsigned 8 bit int8_t - signed 8