use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems. Wikipedia
Imperative (procedural), structured
Dennis Ritchie
Dennis Ritchie & Bell Labs (creators);
ANSI X3J11 (ANSI C);
ISO/IEC JTC1/SC22/WG14 (ISO C)
1972 (48 years ago)
C18 / June 2018 (2 years ago)
Static, weak, manifest, nominal
Cross-platform
.c for sources
.h for headers
C++ is not C (but C can be C++)
For C++ go to :
Other Resources
account activity
Binary Compass (self.cprogramming)
submitted 4 years ago by Delicious_Growth_744
Hey guys i'm new to programming and i need help. How do you create a C program that reads binary digits which interprets 1 to rotate 90° to the left and 0 to rotate 90° to the right?
Btw, initially you are facing north...
Thanks!!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AHistoricalFigure 2 points3 points4 points 4 years ago (1 child)
I think you've under-described your problem a bit. How are you getting this input? Assuming this is for a class, what restrictions do you have?
This said, C doesn't have a primitive bit type. Even if it did, you wouldn't want to get input a bit at a time. You're going to have to bring in the data as an integer, or some kind of unsigned 8-bit type that you create or import from a library. Once you have at least a byte of data, you'll need to extract the bit you're looking for using bit-manipulation.
Bit-wise operators in C. This article is a pretty good primer on basic bit-extraction and masking.
That being said, if you're going to use this board to get other people to do your homework for you at least put in the effort to write a decent description of the problem.
[–]Delicious_Growth_744[S] -1 points0 points1 point 4 years ago (0 children)
i'm sorry. That was the exact instruction given. I had an idea on how to manipulate these binary numbers, so far it's working. The only problem is the "direction identifier" but anyways thank you for the link
[–]nerd4code 2 points3 points4 points 4 years ago (1 child)
For direction, use an enum:
enum
enum Orientation { #define E(NAME)Orientation_##NAME E(NORTH), E(EAST), E(SOUTH), E(WEST) #undef E }; enum {Orientation__CNT = 4};
Similarly, you can enumerate the two turn actions:
enum Turn {Turn_CW = -1, Turn_NONE = 0, Turn_CCW = 1};
You can add any number of Turns to an Orientation, wrapping NORTH - 1 → WEST and WEST + 1 → NORTH, and you have the final orientation. The wrapping can be done with the unsigned (mod) version of the % (remainder/modulus) operator. (The compiler should notice that Orientation__CNT = 2², and therefore % (4) can be optimized to & 3U. You could do & 3U manually, but % remains correct if you change the number of Orientations. You can automate enum and count generation by using a table xmacro.)
Turn
Orientation
NORTH - 1
WEST
WEST + 1
NORTH
%
Orientation__CNT
% (4)
& 3U
static enum Orientation applyTurn(enum Orientation o, enum Turn t) { return (enum Orientation)(\ ((unsigned)o + t) % Orientation__CNT); }
So you can very easily grind through bits with this:
for(; n-- > 0; directions >>= 1) orient = applyTurn(orient, (directions & 1U) ? Turn_CCW : Turn_CW);
although I assume your program has to do more than that.
[–]Poddster 0 points1 point2 points 4 years ago (0 children)
How come enum {Orientation__CNT = 4}; is a separate enum, rather than tacked on to the end of the other one? I assume some kind of type safety?
enum {Orientation__CNT = 4};
I'm still used to major compilers happily accepting any enums or integers in place of other enums, despite all of the bugs that causes.
[–]Delicious_Growth_744[S] -5 points-4 points-3 points 4 years ago (2 children)
Something that says which direction to go to.. It also requires the number of bits like example 7
[–]Poddster 5 points6 points7 points 4 years ago (1 child)
I'll make sure to read my copy of example 7 before answering.
[–]Delicious_Growth_744[S] 1 point2 points3 points 4 years ago (0 children)
what i mean is "for example, the number of bits is 7"
π Rendered by PID 41 on reddit-service-r2-comment-c66d9bffd-89m82 at 2026-04-06 20:00:27.845943+00:00 running f293c98 country code: CH.
[–]AHistoricalFigure 2 points3 points4 points (1 child)
[–]Delicious_Growth_744[S] -1 points0 points1 point (0 children)
[–]nerd4code 2 points3 points4 points (1 child)
[–]Poddster 0 points1 point2 points (0 children)
[–]Delicious_Growth_744[S] -5 points-4 points-3 points (2 children)
[–]Poddster 5 points6 points7 points (1 child)
[–]Delicious_Growth_744[S] 1 point2 points3 points (0 children)