안녕하세요~ c언어대해서 알려주세요

익명 사용자의 이미지

unsigned int string_test[10][5] = {
{0x07, 0x05, 0x05, 0x05, 0x07}, // 0
{0x01, 0x01, 0x01, 0x01, 0x01}, // 1
{0x07, 0x01, 0x07, 0x04, 0x07}, // 2
{0x07, 0x01, 0x07, 0x01, 0x07},//3
{0x05, 0x05, 0x07, 0x01, 0x01},//4
{0x07, 0x04, 0x07, 0x01, 0x07},//5
{0x07, 0x04, 0x07, 0x05, 0x07},//6
{0x07, 0x05, 0x05, 0x01, 0x01},//7
{0x07, 0x05, 0x07, 0x05, 0x07},//8
{0x07, 0x05, 0x07, 0x01, 0x07}//9
}; 

이렇게 정의를 한 후 도트매트릭스에 실시간으로 시간 데이터를 받아 출력하려고 합니다.

사진과 같이 하려고 하는데 특정변수의 특정 비트에 있는 정보를 다른 변수의 특정 비트로 위치시키고 싶은데,,
알려주실수있나요

File attachments: 
첨부파일 크기
Image icon KakaoTalk_20171019_165403284.jpg27.08 KB
세벌의 이미지

질문 뜻을 모르겠네요.
string_test 는 무엇인가요?
첨부파일에서 11:20 과 459는 어떤 관계인가요?

라스코니의 이미지

우선 7-segment 식의 표현은 아닌 것으로 보이는데요
특정 비트를 조작하시려면 C 참고서적의 Bit manipulation 부분을 참고하시면 될 것 같네요.
가령 B 변수의 하위 4 bit를 A 변수의 하위 4 bit에 넣으려면

A = (A & ~0xF) | (B & 0xF);

라고 하시면 됩니다(테스트는 안해 봤습니다).

raymundo의 이미지

특정한 한 비트만 B에서 A로 옮겨오고 싶다면 위에 라스코니님 댓글에서 좀 고쳐서

unsigned char mask = 1 << n;    // n 은 0이면 가장 오른쪽 비트, 7이면 가장 왼쪽 비트
A = (A & ~mask) | (B & mask);

이렇게 하시면 되겠네요.

그런데 굳이 저렇게 0부터 9까지의 모양을 저장한 후 매번 전광판(?) 각 픽셀에 값을 옮기는 것보다 그냥 각 픽셀마다 0~9에 따라서 켜질지 꺼질지를 저장해두시는 게 훨씬 편할 것 같은데요.

// pixel[ x ][ y ][ digit ]
int pixel[3][5][10] = {
  {
    { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 }   // 가장 윗줄 첫번째 픽셀은 값이 1일 때만 꺼지고 나머지는 켜짐
    ...
  }
}

좋은 하루 되세요!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.