Jump to content
Daim2604

C Programming

Recommended Posts

Salam dan selamat sejahtera, 
Pertama sekali saya minta maaf kalau salah section.

Saya nak tnye pasal c programming, ni code sy :

#include <stdio.h>
#include <conio.h>


int main()
{
    int i = 0b11111111;
    printf("%i", i);
    getch();
}

sepatutnya kalau saya run code nya saya akan dapat jawapan 255 tapi saya dapat error

invalid suffix "b11111111" on integer constant .. 

sy pakai Code Block 12.11 .. minta bantuan rakan2 , saya masih baru dalam bidang c programming, dan memang minat dalam bidang2 code2 ni .. Thanks ye..

 

Share this post


Link to post
Share on other sites

wslm

 

Compiler tak support kot... Codeblocks 12.11 tu guna compiler apa version berapa?

 

saya x pasti plak bang, maaf sngt2 sy nie baru lagi , sy ni pun belajar sndiri je main langgar je.. tapi kalau x salah sy GCC , ni saya petik dari webpage code block 

 

GCC compiler and GDB debugger from TDM-GCC(version 4.7.1, 32 bit).

Ke code block ni x bagus ? ada yang lebih baik ke?

Share this post


Link to post
Share on other sites

rasanya binary constant tu yang tak standard, saya try kat compiler vstudio2010 pun xleh...

 

int i = 0b11111111;

 

eloklah tukar jadi

 

int i 0xff; atau yang serupa... int i = 255..

Share this post


Link to post
Share on other sites

0xff ni hexadecimal....

 

0xff (hex) = 255 (decimal) = 1111 1111 (binary)

 

kalau dari binari ke hexadecimal,

4 bit/1111 = 0xf

8 bit/1111 1111 = 0xff

 

nombor2 hexadecimal ni ada nombor biasa 0-9 pastu tambahan a-f, kira base 16...:

0

1

2

3

4

5

6

7

8

9

a

b

c

d

e

f

 

lepas f akan jadi 10, kemudian 11,12,13,14,15,16,17,18,19,1a,1b,1c,...

 

boleh rujuk internet kalau nak faham lebih lanjut...

 

btw binary constant memang tak standard... jadi kebanyakan compiler tak boleh compile, version gcc tertentu je ada extension untuk support binary constant ni...

Edited by syahmixp

Share this post


Link to post
Share on other sites

0xff ni hexadecimal....

 

0xff (hex) = 255 (decimal) = 1111 1111 (binary)

 

kalau dari binari ke hexadecimal,

4 bit/1111 = 0xf

8 bit/1111 1111 = 0xff

 

nombor2 hexadecimal ni ada nombor biasa 0-9 pastu tambahan a-f, kira base 16...:

0

1

2

3

4

5

6

7

8

9

a

b

c

d

e

f

 

lepas f akan jadi 10, kemudian 11,12,13,14,15,16,17,18,19,1a,1b,1c,...

 

boleh rujuk internet kalau nak faham lebih lanjut...

 

btw binary constant memang tak standard... jadi kebanyakan compiler tak boleh compile, version gcc tertentu je ada extension untuk support binary constant ni...

 

 

Terima kasih banyak2 bang , sy ingatkan binary dengan decimal je yang ada, huhu , cetek nya ilmu saya , thanks bnyk2 ye yg sudi tolong juga..

Share this post


Link to post
Share on other sites

binary biasanya banyak digunakan dalam firmware coding. Most embedded C compiler biasanya support binary constant. Untuk application computer xbanyak support binary constant. Better pakai decimal atau hexadecimal. Octadecimal penah dengar?

Share this post


Link to post
Share on other sites

saya baru nak belajar benda tu , tapi sangkut dekat binary ni ,hehe .. minta maaf, boleh tak sapa2 terangkan skit pada sy , hexadecimal & octadecimal ni ni apa? decimal ni saya rasa saya faham , die ni nombor biasa kan? 

Thanks dan maaf ye 

Share this post


Link to post
Share on other sites

boleh saya tau asal kod tu (dapat dari mana)?
 
daim, ko belajar sendiri programming ke?

Maaf lambat bang. Saya tngk tutorial di youtube mcm tu je. Tapi susah sikit tngk tutorial ni , tmpat bertanya tak de..hehe. Kod tu pun sy dapat dari user buat tutorial tu , skjap ye sy letak video skli ,
 

 https://www.youtube.com/watch?v=6_1AWHz4RRY

 

dkat situ la sy tngk tutorial, tpi video nye pun x banyak nanti mungkin kene pindah cari tutorial lain plak

Edited by Daim2604

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...