Jump to content
PirateClub.hu

Char to Bin


BasketWink
 Share

Recommended Posts

Hali,

 

a gondom hogy haskellben karaktert kellene kettes számrendszerben megjeleníteni úgy hogy 8 karakter hosszú legyen ha nicns annyi akkor az elejéhez hozzá rakjon a progi 0-ákat. de valamiért nem működik :S

 

itt van a hibakód:

error_www.kepfeltoltes.hu_.jpg

 

és itt a progi kód:

import Data.Char (ord)
toBinary :: Int -> [Int]
toBinary 0 = []
toBinary x = reverse (kisegf x)
kisegf 0 = []
kisegf x | x `mod` 2 == 1 = 1 : kisegf (x `div` 2)
         | x `mod` 2 == 0 = 0 : kisegf (x `div` 2)
chrToBinary :: Char -> [Int]
chrToBinary x | length (kisegf2 x) == 8 = kisegf2 x
              | length (kisegf2 x) <8 = ((kisegf2 x) ++ 0)
kisegf2 0 = []
kisegf2 x = toBinary(ord 'x')

 

köszi

W

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Hozzászólás a témához...

×   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.

 Share

  • Jelenleg olvassa   0 members

    • No registered users viewing this page.
×
×
  • Create New...